Part Number Hot Search : 
TM128 MBM29 0512S AD8609AR GA168P 2SC4177 1N5355 SC454
Product Description
Full Text Search
 

To Download C8051F980 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ultra low power, 8-2 kb flas h, capacitive sensing mcu c8051f99x-c8051f98x rev. 1.0 11/10 copyright ? 2010 by silicon laboratories c8051f99x-c8051f98x ultra low power consumption - 150 a/mhz in active mode (24.5 mhz clock) - 2 s wakeup time - 10 na sleep mode with memory retention - 50 na sleep mode with brownout detector - 300 na sleep mode with lfo - 600 na sleep mode with external crystal supply voltage 1.8 to 3.6 v - built-in ldo regulator allows a high analog supply voltage and low digital core voltage - 2 built-in supply monitors (brownout detector) for sleep mode and active modes 12-bit or 10-bit analog to digital converter - 1 lsb inl (10-bit mode); 1.5 lsb inl ? (12-bit mode) no missing codes - programmable throughput up to 300 ksps ? (10-bit mode) or 75 ksps (12-bit mode) - up to 10 external inputs - on-chip voltage reference; 0.5x gain allows measur - ing voltages up to twice the reference voltage - 16-bit auto-averaging accumulator with burst mode provides increased adc resolution - data dependent windowed interrupt generator - built-in temperature sensor capacitive sense interface (f99x) - supports buttons, sliders, wheels, and capacitive proximity sensing - fast 40 s per channel conversion time - 16-bit resolution, up to 14 input channels - auto scan and wake-on-touch - auto-accumulate up to 64x samples analog comparator - programmable hysteresis and response time - configurable as wake-up or reset source 6-bit programmable current reference - up to 500 a, can be used as a bias or for generating a custom reference voltage - pwm enhanced resolution mode high-speed 8051 c core - pipelined instruction architecture; executes 70% of instructions in 1 or 2 system clocks - up to 25 mips throughput with 25 mhz clock - expanded interrupt handler memory - 512 bytes ram - 8 kb (f990/1/6/7, f980/1/6/7), 4 kb (f982/3/8/9), or 2 kb (f985) flash; in-system programmable digital peripherals - up to 17 port i/o; high sink current and programmable drive strength ? hardware smbus?/i 2 c?, spi?, and uart serial ports available concurrently - four general purpose 16-bit counter/timers - programmable 16-bit counter/timer array with three capture/compare modules and watchdog timer clock sources - internal oscillators: 24.5 mhz, 2% accuracy supports uart operation; 20 mhz low power oscillator requires very little bias current. - external oscillator: crystal, rc, c, or cmos clock - smartclock oscillator: 32 khz crystal or internal - can switch between clock s ources on-the-fly; useful in implementing various power saving modes on-chip debug - on-chip debug circuitry fac ilitates full-speed, non- intrusive in-system debug (no emulator required) - provides breakpoints, single stepping - inspect/modify memory and registers - complete development kit packages - 20-pin qfn (3 x 3 mm) - 24-pin qfn (4 x 4 mm) - 24-pin qsop (easy to hand-solder) temperature range: ?40 to +85 c analog peripherals 12/10-bit 75/300 ksps adc 8/4/2 kb isp flash 512b sram por debug circuitry flexible interrupts 8051 cpu (25 mips) temp sensor digital i/o 24.5 mhz precision internal oscillator high-speed controller core a m u x crossbar voltage comparator + ? wdt uart smbus pca timer 0 timer 1 timer 2 timer 3 port 0 spi iref port 1 port 2 vreg 20 mhz low power internal oscillator vref crc hardware smartclock external oscillator capacitive sense www.datasheet.in
c8051f99x-c8051f98x 2 rev. 1.0 table of contents 1. system overview............ ................ ................ ................. .............. .............. ........... 17 1.1. cip-51? microcontroller core.. ................ ................. .............. .............. ........... 25 1.1.1. fully 8051 compatible...... ................ ................. .............. .............. ........... 25 1.1.2. improved throughput ............ .............. .............. .............. .............. ........... 25 1.1.3. additional features .......... ................ ................. .............. .............. ........... 25 1.2. port input/output....... ................ ................ ................. .............. .............. ........... 26 1.3. serial ports ............ ................. ................ ................ ................. .............. ........... 27 1.4. programmable counter array ... ................ ................. .............. .............. ........... 27 1.5. sar adc with 16-bi t auto-averaging accumu lator and autonomous ? low power burst mode.... .............. .............. .............. .............. .............. ........... 28 1.6. programmable current reference (iref0) ..... .............. ............... ........... ......... 29 1.7. comparator ............... ................ ................ ................. .............. .............. ........... 29 2. ordering information...... ................ ................ ................. .............. .............. ........... 31 3. pinout and package definitions..... ............... ................. .............. .............. ........... 32 4. electrical characteristics.......... ................. ................ ................. ................ ........... 46 4.1. absolute maximum specificati ons ...................... ................ ................. ............. 46 4.2. electrical characterist ics.................. .............. .............. .............. .............. ......... 47 5. sar adc with 16-bit auto -averaging accumulator and ? autonomous low power burst mode .............. .............. .............. .............. ........... 64 5.1. output code formatting ......... ................ ................ ................. .............. ........... 65 5.2. modes of operation ............. ................. ................ ................. ................ ........... 66 5.2.1. starting a conversion....... ................ ................. .............. .............. ........... 66 5.2.2. tracking modes................ ................ ................. .............. .............. ........... 67 5.2.3. burst mode ........... ................. .............. .............. .............. .............. ........... 68 5.2.4. settling time r equirements ................ .............. .............. .............. ........... 69 5.2.5. gain setting........ ................ ................. .............. .............. .............. ........... 70 5.3. 8-bit mode.......... ................ ................ ................. ................ ................. ............. 70 5.4. 12-bit mode (C8051F980/6 a nd c8051f990/6 devices only). ............... ........... 70 5.5. low power mode ........ ................ ................. .............. .............. .............. ........... 70 5.6. programmable window detector ................. .............. .............. .............. ........... 78 5.6.1. window detector in sing le-ended mode .......... .............. .............. ........... 80 5.6.2. adc0 specifications......... ................ ................. .............. .............. ........... 80 5.7. adc0 analog multiplexer........ ................ ................ ................. .............. ........... 81 5.8. temperature sensor ............ ................. ................ ................. ................ ........... 83 5.8.1. calibration .......... ................ ................. .............. .............. .............. ........... 84 5.9. voltage and ground reference options............... ................. ................ ........... 86 5.10.external voltage reference...... ................ ................. .............. .............. ........... 87 5.11.internal voltage reference..... ................ ................ ................. .............. ........... 87 5.12.analog ground referenc e................. ................. ................ ................. ............. 87 5.13.temperature sensor enable .... ................ ................. .............. .............. ........... 87 5.14.voltage reference electrical specifications .. .............. .............. .............. ......... 88 6. programmable current reference (iref0) ....... .............. .............. .............. ......... 89 6.1. pwm enhanced mode .............. ................ ................. .............. .............. ........... 89 www.datasheet.in
rev. 1.0 3 c8051f99x-c8051f98x 6.2. iref0 specifications............ ................. ................ ................. ................ ........... 90 7. comparator ........... ................. .............. .............. .............. .............. .............. ........... 91 7.1. comparator inputs .... ................ ................ ................. .............. .............. ........... 91 7.2. comparator outputs ............ ................. ................ ................. ................ ........... 92 7.3. comparator response time................. ................ ................. ................ ........... 92 7.4. comparator hysteresis ............... ................. .............. .............. .............. ........... 92 7.5. comparator register descripti ons...................... ................ ................. ............. 93 7.6. comparator0 analog multiplexe r ................. .............. .............. .............. ........... 96 8. capacitive sense (cs0)........... ................ ................. ................ ................. ............. 98 8.1. configuring port pins as capacitive sense inputs ........... ............ ........... ......... 99 8.2. initializing the capac itive sensing peripheral .............. .............. .............. ......... 99 8.3. capacitive sense start-of -conversion sources............... ............ ........... ......... 99 8.4. cs0 multiple channel enable ... ................ ................. .............. .............. ......... 100 8.5. cs0 gain adjustment .......... ................. ................ ................. ................ ......... 100 8.6. wake from suspend ... ................ ................. .............. .............. .............. ......... 100 8.7. using cs0 in applications that utilize sleep mode........ ............... ........... ....... 100 8.8. automatic scanning (met hod 1?cs0smen = 0) .............. ................. ........... 101 8.9. automatic scanning (met hod 2?cs0smen = 1) .............. ................. ........... 102 8.10.cs0 comparator......... ................ ................. .............. .............. .............. ......... 102 8.11.cs0 conversion accumulator ... ............... ................. .............. .............. ......... 103 8.12.cs0 pin monitor ....... ................ ................ ................. .............. .............. ......... 104 8.13.adjusting cs0 for special situations.......... .............. .............. .............. ......... 105 8.14.capacitive sense multiplexer ... ................ ................. .............. .............. ......... 116 9. cip-51 microcontroller .............. ................. ................ ................. ................ ......... 118 9.1. performance ............. ................ ................ ................. .............. .............. ......... 118 9.2. programming and debugging suppor t ............... ................ ................. ........... 119 9.3. instruction set ........... ................ ................ ................. .............. .............. ......... 119 9.3.1. instruction and cpu timing .. .............. .............. .............. .............. ......... 119 9.4. cip-51 register descriptions.... ................ ................. .............. .............. ......... 124 10. memory organization..... ................ ................ ................. .............. .............. ......... 127 10.1.program memory........ ................ ................. .............. .............. .............. ......... 128 10.1.1.movx instruction and pr ogram memory .......... .............. .............. ......... 128 10.2.data memory ............ ................ ................ ................. .............. .............. ......... 128 10.2.1.internal ram ........ ................. .............. .............. .............. .............. ......... 128 10.2.2.external ram ....... ................. .............. .............. .............. .............. ......... 129 11. on-chip xram......... ................ ................ ................. ................ ................. ........... 130 11.1.accessing xram.......... ................. .............. .............. .............. .............. ......... 130 11.1.1.16-bit movx example ....... ................. .............. .............. .............. ......... 130 11.1.2.8-bit movx example ......... ................. .............. .............. .............. ......... 130 12. special function registers ...... ................. ................ ................. ................ ......... 131 12.1.sfr paging .............. ................ ................ ................. .............. .............. ......... 132 13. interrupt handler ............ ................ ................ ................. .............. .............. ......... 137 13.1.enabling interrupt sources ..... ................ ................ ................. .............. ......... 137 13.2.mcu interrupt source s and vectors.............. .............. .............. .............. ....... 137 13.3.interrupt priorities ..... ................ ................ ................. .............. .............. ......... 138 www.datasheet.in
c8051f99x-c8051f98x 4 rev. 1.0 13.4.interrupt latency....... ................ ................ ................. .............. .............. ......... 138 13.5.interrupt register de scriptions ............. ................ ................. ................ ......... 140 13.6.external interrupts int0 and int1 ................. .............. .............. .............. ....... 147 14. flash memory ................. ................ ................ ................. .............. .............. ......... 149 14.1.programming the flash memory ................. .............. .............. .............. ......... 149 14.1.1.flash lock and key functi ons ................ .............. ............... ........... ....... 149 14.1.2.flash erase procedure ...... ................. .............. .............. .............. ......... 150 14.1.3.flash write procedure ..... ................ ................. .............. .............. ......... 150 14.2.non-volatile data storage ... ................. ................ ................. ................ ......... 150 14.3.security options ....... ................ ................ ................. .............. .............. ......... 151 14.4.determining the devi ce part number at run time ..... .............. .............. ....... 153 14.5.flash write and erase guidelines ............... .............. .............. .............. ......... 155 14.5.1.v dd maintenance and the v dd monitor ............ .............. .............. ......... 155 14.5.2.pswe maintenance ......... ................ ................. .............. .............. ......... 156 14.5.3.system clock ....... ................. .............. .............. .............. .............. ......... 156 14.6.minimizing flash read current .. ................. .............. .............. .............. ......... 157 15. power management........ ................ ................ ................. .............. .............. ......... 161 15.1.normal mode ............ ................ ................ ................. .............. .............. ......... 162 15.2.idle mode............... ................. ................ ................ ................. .............. ......... 163 15.3.stop mode ......... ................ ................ ................. ................ ................. ........... 163 15.4.suspend mode ............. ................. .............. .............. .............. .............. ......... 164 15.5.sleep mode .............. ................ ................ ................. .............. .............. ......... 164 15.6.configuring wakeup sources... ................ ................. .............. .............. ......... 165 15.7.determining the event that caused the last wakeup... ............... ........... ....... 165 15.8.power management spec ifications ........ ................ ................. .............. ......... 169 16. cyclic redundancy check unit ( crc0) .............. .............. ............... ........... ....... 170 16.1.crc algorithm............ ................ ................. .............. .............. .............. ......... 170 16.2.preparing for a crc ca lculation .......... ................ ................. ................ ......... 172 16.3.performing a crc calculation . ................ ................. .............. .............. ......... 172 16.4.accessing the crc0 result ..... ................ ................. .............. .............. ......... 172 16.5.crc0 bit reverse feat ure.............. .............. .............. .............. .............. ....... 177 17. voltage regulator (vreg0) ...... ................. ................ ................. ................ ......... 178 17.1.voltage regulator elec trical specifications ............... .............. .............. ......... 178 18. reset sources.......... ................ ................ ................. ................ ................. ........... 179 18.1.power-on reset ....... ................ ................ ................. .............. .............. ......... 180 18.2.power-fail reset ........ ................ ................. .............. .............. .............. ......... 180 18.3.external reset .......... ................ ................ ................. .............. .............. ......... 182 18.4.missing clock detector reset ... ............... ................. .............. .............. ......... 182 18.5.comparator0 reset ............. ................. ................ ................. ................ ......... 183 18.6.pca watchdog timer reset ..... ............... ................. .............. .............. ......... 183 18.7.flash error reset ..... ................ ................ ................. .............. .............. ......... 183 18.8.smartclock (real time clock) reset ................ ................. ................ ......... 183 18.9.software reset ......... ................ ................ ................. .............. .............. ......... 184 19. clocking sources ........... ................ ................ ................. .............. .............. ......... 186 19.1.programmable precision inte rnal oscillator ....... ................ ................. ........... 187 www.datasheet.in
rev. 1.0 5 c8051f99x-c8051f98x 19.2.low power internal oscillator. ................ ................ ................. .............. ......... 187 19.3.external oscillator drive circuit................ ................. .............. .............. ......... 187 19.3.1.external crystal mode...... ................ ................. .............. .............. ......... 187 19.3.2.external rc mode... .............. .............. .............. .............. .............. ......... 189 19.3.3.external capacitor mode.. ................ ................. .............. .............. ......... 190 19.3.4.external cmos clock mode ................. .............. .............. .............. ....... 190 19.4.special function registers for select ing and configuring the system clock 191 20. smartclock (real time clock) .. ................ ................ ................. .............. ......... 195 20.1.smartclock interface .... .............. .............. .............. .............. .............. ......... 196 20.1.1.smartclock lock and key functions......... ................. ................ ......... 196 20.1.2.using rtc0adr and rtc0dat to access smartclock ? internal registers ............... ................. .............. .............. .............. ......... 197 20.1.3.rtc0adr short stro be feature............. .............. ............... ........... ....... 197 20.1.4.smartclock interface auto read feature .................. ................. ........... 197 20.1.5.rtc0adr autoincrement feature.......... .............. ............... ........... ....... 198 20.2.smartclock clocking sources . ................. .............. .............. .............. ......... 201 20.2.1.using the smartclock o scillator with a crystal or ? external cmos clock ........... .............. .............. .............. .............. ......... 201 20.2.2.using the smartclock o scillator in self-oscillate mo de............. ......... 202 20.2.3.using the low fr equency oscillator (lfo) ........... ............... ........... ....... 202 20.2.4.programmable load capacitance.............. ................ ................. ........... 203 20.2.5.automatic gain control (c rystal mode only) and smartclock ? bias doubling ............ ................ ................. ................ ................. ........... 204 20.2.6.missing smartclock detect or ............... .............. ............... ........... ....... 206 20.2.7.smartclock oscillator cryst al valid detector .......... ................. ........... 206 20.3.smartclock timer and alarm function .............. ................. ................ ......... 206 20.3.1.setting and reading the smartclock timer value ..... ................ ......... 206 20.3.2.setting a smartclock alar m ................. .............. ............... ........... ....... 207 20.3.3.software considerat ions for using the smartclock timer and alarm . 208 21. port input/output............ ................ ................ ................. .............. .............. ......... 213 21.1.port i/o modes of operation ................. ................ ................. ................ ......... 214 21.1.1.port pins configured for analog i/o............. ................. ................ ......... 214 21.1.2.port pins configured for digital i/o...... .............. .............. .............. ....... 214 21.1.3.interfacing port i/o to 5 v logic .......... .............. .............. .............. ......... 215 21.1.4.increasing port i/ o drive strength ... ................. .............. .............. ......... 215 21.2.assigning port i/o pins to analog and digital functions.. ............ ........... ....... 215 21.2.1.assigning port i/o pins to analog functions ...... .............. .............. ....... 215 21.2.2.assigning port i/o pins to digital func tions............. ............ ........... ....... 216 21.2.3.assigning port i/o pi ns to external digital ev ent capture functions .... 216 21.3.priority crossbar decoder ... ................. ................ ................. ................ ......... 217 21.4.port match ............. ................. ................ ................ ................. .............. ......... 223 21.5.special function register s for accessing and c onfiguring port i/ o .............. 225 22. smbus ................. ................ ................. .............. .............. .............. .............. ......... 233 22.1.supporting documents ............. ................ ................. .............. .............. ......... 234 22.2.smbus configuration... ............... ................. .............. .............. .............. ......... 234 www.datasheet.in
c8051f99x-c8051f98x 6 rev. 1.0 22.3.smbus operation ....... ................ ................. .............. .............. .............. ......... 235 22.3.1.transmitter vs. receiver .. ................ ................. .............. .............. ......... 235 22.3.2.arbitration......... ................ ................ ................. .............. .............. ......... 235 22.3.3.clock low extension........ ................ ................. .............. .............. ......... 236 22.3.4.scl low timeout.... .............. .............. .............. .............. .............. ......... 236 22.3.5.scl high (smbus free) ti meout .............. ................ ................. ........... 236 22.4.using the smbus........ ................ ................. .............. .............. .............. ......... 237 22.4.1.smbus configuration regist er................ .............. ............... ........... ....... 238 22.4.2.smb0cn control register . ................. .............. .............. .............. ......... 241 22.4.3.hardware slave address recognition ........... ................. .............. ......... 244 22.4.4.data register ....... ................. .............. .............. .............. .............. ......... 246 22.5.smbus transfer modes... .............. .............. .............. .............. .............. ......... 247 22.5.1.write sequence (master) ...... .............. .............. .............. .............. ......... 247 22.5.2.read sequence (master) ...... .............. .............. .............. .............. ......... 248 22.5.3.write sequence (slave) ........ .............. .............. .............. .............. ......... 249 22.5.4.read sequence (slave) ........ .............. .............. .............. .............. ......... 250 22.6.smbus status decoding ................ .............. .............. .............. .............. ......... 250 23. uart0................ ................ ................ ................. .............. .............. .............. ......... 255 23.1.enhanced baud rate g eneration.................. .............. .............. .............. ....... 256 23.2.operational modes ....... ................. .............. .............. .............. .............. ......... 257 23.2.1.8-bit uart ........... ................. .............. .............. .............. .............. ......... 257 23.2.2.9-bit uart ........... ................. .............. .............. .............. .............. ......... 258 23.3.multiprocessor communications ... .............. .............. .............. .............. ......... 258 24. enhanced serial peripheral interface (spi0)..... .............. .............. .............. ....... 263 24.1.signal descriptions....... ................. .............. .............. .............. .............. ......... 264 24.1.1.master out, slave in (mos i)...................... ................ ................. ........... 264 24.1.2.master in, slave out (miso)............... .............. .............. .............. ......... 264 24.1.3.serial clock (sck) ........... ................ ................. .............. .............. ......... 264 24.1.4.slave select (nss) .......... ................ ................. .............. .............. ......... 264 24.2.spi0 master mode operation . ................ ................ ................. .............. ......... 264 24.3.spi0 slave mode operation ..... ................ ................. .............. .............. ......... 266 24.4.spi0 interrupt sources ........ ................. ................ ................. ................ ......... 267 24.5.serial clock phase and polari ty ............. ................ ................. .............. ......... 267 24.6.spi special function registers . ............... ................. .............. .............. ......... 269 25. timers................ ................ ................ .............. .............. ............... .............. ........... 27 6 25.1.timer 0 and ti mer 1 ............... ................ ................ ................. .............. ......... 278 25.1.1.mode 0: 13-bit counter/timer ................. .............. ............... ........... ....... 278 25.1.2.mode 1: 16-bit counter/timer ................. .............. ............... ........... ....... 279 25.1.3.mode 2: 8-bit counter/tim er with auto-reload.......... ................. ........... 280 25.1.4.mode 3: two 8-bit counter /timers (timer 0 only)..... ................. ........... 281 25.2.timer 2 ............. ................ ................ ................. ................ ................. ........... 286 25.2.1.16-bit timer with auto-rel oad............... .............. .............. .............. ....... 286 25.2.2.8-bit timers with auto-rel oad............... .............. .............. .............. ....... 287 25.2.3.comparator 0/smartclo ck capture mode ............... ................. ........... 288 25.3.timer 3 ............. ................ ................ ................. ................ ................. ........... 292 www.datasheet.in
rev. 1.0 7 c8051f99x-c8051f98x 25.3.1.16-bit timer with auto-rel oad............... .............. .............. .............. ....... 292 25.3.2.8-bit timers with auto-r eload .............. .............. .............. .............. ....... 293 25.3.3.smartclock/external osci llator capture mode ........ ................. ........... 294 26. programmable counter array ....... ................ ................. .............. .............. ......... 298 26.1.pca counter/timer ............. ................. ................ ................. ................ ......... 299 26.2.pca0 interrupt sources....... ................. ................ ................. ................ ......... 300 26.3.capture/compare modules ...... ................ ................. .............. .............. ......... 301 26.3.1.edge-triggered captur e mode................. .............. ............... ........... ....... 302 26.3.2.software timer (compare) mode................. ................. ................ ......... 303 26.3.3.high-speed output mode ..... .............. .............. .............. .............. ......... 304 26.3.4.frequency output mode ....... .............. .............. .............. .............. ......... 304 26.3.5. 8-bit, 9-bit, 10-bit and 11-bit pulse width modula tor modes ................. 305 26.3.6. 16-bit pulse width modul ator mode....... .............. ............... ........... ....... 308 26.4.watchdog timer mode .... .............. .............. .............. .............. .............. ......... 309 26.4.1.watchdog timer operation ... .............. .............. .............. .............. ......... 309 26.4.2.watchdog timer usage ........ .............. .............. .............. .............. ......... 310 26.5.register descriptions for pca0 ................ ................. .............. .............. ......... 311 27. c2 interface ................ ................ ................. ................ ................. ................ ......... 317 27.1.c2 interface registers......... ................. ................ ................. ................ ......... 317 27.2.c2 pin sharing ......... ................ ................ ................. .............. .............. ......... 320 document change list............... .............. .............. .............. .............. .............. ........ 321 contact information.......... ................. ................ ................ ................. .............. ........ 322 www.datasheet.in
c8051f99x-c8051f98x 8 rev. 1.0 list of figures figure 1.1. C8051F980 block diagr am ...................... ................ ................. ............. 18 figure 1.2. c8051f981 block diagr am ...................... ................ ................. ............. 18 figure 1.3. c8051f982 block diagr am ...................... ................ ................. ............. 19 figure 1.4. c8051f983 block diagr am ...................... ................ ................. ............. 19 figure 1.5. c8051f985 block diagr am ...................... ................ ................. ............. 20 figure 1.6. c8051f986 block diagr am ...................... ................ ................. ............. 20 figure 1.7. c8051f987 block diagr am ...................... ................ ................. ............. 21 figure 1.8. c8051f988 block diagr am ...................... ................ ................. ............. 21 figure 1.9. c8051f989 block diagr am ...................... ................ ................. ............. 22 figure 1.10. c8051f990 bl ock diagram ............... .............. .............. .............. ......... 22 figure 1.11. c8051f991 bl ock diagram ............... .............. .............. .............. ......... 23 figure 1.12. c8051f996 bl ock diagram ............... .............. .............. .............. ......... 23 figure 1.13. c8051f997 bl ock diagram ............... .............. .............. .............. ......... 24 figure 1.14. port i/o functional block diagram ................ .............. .............. ........... 26 figure 1.15. pca block diagram.... ................ ................ ................. .............. ........... 27 figure 1.16. adc0 functional bl ock diagram.............. ................. ................ ........... 28 figure 1.17. adc0 multiplexer block diagram .... .............. .............. .............. ........... 29 figure 1.18. comparator 0 func tional block diagram .. ................ ................ ........... 30 figure 3.1. qfn-20 pinout diagr am (top view) .......... ................. ................ ........... 35 figure 3.2. qfn-24 pinout diagr am (top view) .......... ................. ................ ........... 36 figure 3.3. qsop-24 pi nout diagram (top view)... .............. ............... ........... ......... 37 figure 3.4. qfn-20 package drawin g ................ .............. .............. .............. ........... 38 figure 3.5. typical qfn-20 landi ng diagram.............. ................. ................ ........... 39 figure 3.6. qfn-24 package drawin g ................ .............. .............. .............. ........... 41 figure 3.7. typical qfn-24 landi ng diagram.............. ................. ................ ........... 42 figure 3.8. qsop-24 pa ckage diagram ............. .............. .............. .............. ........... 44 figure 3.9. qsop-24 land ing diagram ......... ................ ................. .............. ........... 45 figure 4.1. active mode curr ent (external cmos clock) ..... ............... ........... ......... 50 figure 4.2. idle mode current (external cmos clock) ......... ............... ........... ......... 51 figure 4.3. typical voh curves, 1.8?3.6 v ............... ................ ................. ............. 53 figure 4.4. typical vol curves, 1.8?3.6 v ......... .............. .............. .............. ........... 54 figure 5.1. adc0 functional bl ock diagram.............. ................ ................. ............. 64 figure 5.2. 10-bit adc tr ack and conversion example timing (bursten = 0).... 67 figure 5.3. burst mode tracking example wit h repeat count set to 4 .......... ......... 68 figure 5.4. adc0 equivalent i nput circuits ............. .............. ............... ........... ......... 69 figure 5.5. adc window co mpare example: right-justi fied single-ended data ... 80 figure 5.6. adc window co mpare example: left-justif ied single-ended data...... 80 figure 5.7. adc0 multiplexer bl ock diagram ............. ................ ................. ............. 81 figure 5.8. temperature sensor transfer function .............. ............... ........... ......... 83 figure 5.9. temperature sensor error with 1-point calibration (v ref = 1.65 v) ..... 84 figure 5.10. voltage re ference functional block diagram.. ............. .............. ......... 86 figure 7.1. comparator 0 func tional block diagram ............... ............ ........... ......... 91 figure 7.2. comparator hysteres is plot ........... ................. .............. .............. ........... 93 www.datasheet.in
rev. 1.0 9 c8051f99x-c8051f98x figure 7.3. cp0 multiplexer blo ck diagram................ ................ ................. ............. 96 figure 8.1. cs0 block diagram ... ................. ................ ................. ................ ........... 98 figure 8.2. auto-scan example... ................. ................ ................. ................ ......... 101 figure 8.3. cs0 multiplexer blo ck diagram................ ................ ................. ........... 116 figure 9.1. cip-51 block diagram.. ................ ................ ................. .............. ......... 118 figure 10.1. c8051f99x-c8051f98x memory map ... ................ ................. ........... 127 figure 10.2. flash program memo ry map.................. ................ ................. ........... 128 figure 14.1. flash program me mory map (8 kb and smaller devices) ....... ........... 151 figure 15.1. c8051f99x-c8051f98x power distribution........... ................. ........... 162 figure 16.1. crc0 block diagram .. ............... ................ ................. .............. ......... 170 figure 16.2. bit reverse register ................ ................ ................. ................ ......... 177 figure 18.1. reset sources......... ................. ................ ................. ................ ......... 179 figure 18.2. power-fail reset timing diagram ........... ................. ................ ......... 180 figure 19.1. clocking sources bl ock diagram ............. ................. ................ ......... 186 figure 19.2. 25 mhz external cr ystal example.......... ................ ................. ........... 188 figure 20.1. smartclock block di agram............. .............. .............. .............. ....... 195 figure 20.2. interpreting oscillation robustn ess (duty cycle) test results.......... 204 figure 21.1. port i/o functional block diagram ................ .............. .............. ......... 213 figure 21.2. port i/o ce ll block diagram ............ .............. .............. .............. ......... 214 figure 21.3. peripheral availabi lity on port i/o pins .............. ............... ........... ....... 217 figure 21.4. crossbar priority decoder in example configuration ? (no pins skipped) ............. .............. .............. .............. .............. ......... 218 figure 21.5. crossbar priority decoder in example configuration ? (4 pins skipped) ............... .............. .............. .............. .............. ......... 218 figure 22.1. smbus block diagram .. ............... ................. .............. .............. ......... 233 figure 22.2. typical smbus configuration .......... .............. .............. .............. ......... 234 figure 22.3. smbus transaction .... ................ ................ ................. .............. ......... 235 figure 22.4. typical smbus scl generation........ .............. .............. .............. ....... 238 figure 22.5. typical master wr ite sequence ............... ................. ................ ......... 247 figure 22.6. typical ma ster read sequence ........ .............. .............. .............. ....... 248 figure 22.7. typical sl ave write sequence ... ................ ................. .............. ......... 249 figure 22.8. typical slave read sequence ................. ................. ................ ......... 250 figure 23.1. uart0 block diagram ............. ................ ................. ................ ......... 255 figure 23.2. uart0 baud rate logi c ................. .............. .............. .............. ......... 256 figure 23.3. uart interconnect di agram ............. .............. .............. .............. ....... 257 figure 23.4. 8-bit uart timing diagram............ .............. .............. .............. ......... 257 figure 23.5. 9-bit uart timing diagram............ .............. .............. .............. ......... 258 figure 23.6. uart multi-proc essor mode interconne ct diagram .......... ................ 259 figure 24.1. spi block di agram .............. .............. .............. .............. .............. ....... 263 figure 24.2. multiple-master mode connection diagram ................ .............. ......... 265 figure 24.3. 3-wire single master and 3-wire single slave mode ? connection diagram ............. ................. ................ ................. ........... 265 figure 24.4. 4-wire single master mode and 4-wire slave mode ? connection diagram ............. ................. ................ ................. ........... 266 figure 24.5. master mode data/ clock timing .............. ................. ................ ......... 268 www.datasheet.in
c8051f99x-c8051f98x 10 rev. 1.0 figure 24.6. slave mode data/clock timing (ckpha = 0) ... ............... ........... ....... 268 figure 24.7. slave mode data/clock timing (ckpha = 1) ... ............... ........... ....... 269 figure 24.8. spi master timing (ckpha = 0)..... .............. .............. .............. ......... 273 figure 24.9. spi master timing (ckpha = 1)..... .............. .............. .............. ......... 273 figure 24.10. spi slave timing (c kpha = 0).............. ................. ................ ......... 274 figure 24.11. spi slave timing (c kpha = 1).............. ................. ................ ......... 274 figure 25.1. t0 mode 0 bl ock diagram............... .............. .............. .............. ......... 279 figure 25.2. t0 mode 2 bl ock diagram............... .............. .............. .............. ......... 280 figure 25.3. t0 mode 3 bl ock diagram............... .............. .............. .............. ......... 281 figure 25.4. timer 2 16-bit mode block diagram ........ ................. ................ ......... 286 figure 25.5. timer 2 8-bit mode block diagram ................... ............... ........... ....... 287 figure 25.6. timer 2 ca pture mode block diagram .............. ............... ........... ....... 288 figure 25.7. timer 3 16-bit mode block diagram ........ ................. ................ ......... 292 figure 25.8. timer 3 8-bit mode block diagram ................... ............... ........... ....... 293 figure 25.9. timer 3 ca pture mode block diagram .............. ............... ........... ....... 294 figure 26.1. pca block diagram.... ................ ................ ................. .............. ......... 298 figure 26.2. pca counter/timer block diagram.......... ................. ................ ......... 299 figure 26.3. pca interrupt blo ck diagram ................. ................ ................. ........... 300 figure 26.4. pca capture mode dia gram............. .............. .............. .............. ....... 302 figure 26.5. pca software time r mode diagram ........ ................. ................ ......... 303 figure 26.6. pca high-speed out put mode diagram....... .............. .............. ......... 304 figure 26.7. pca frequen cy output mode ........... .............. .............. .............. ....... 305 figure 26.8. pca 8-bit pwm mode diagram ............... ................. ................ ......... 306 figure 26.9. pca 9, 10 and 11-bi t pwm mode diagram .. .............. .............. ......... 307 figure 26.10. pca 16-bit pwm mode ................. .............. .............. .............. ......... 308 figure 26.11. pca module 2 with watchdog ti mer enabled ..... ................. ........... 309 figure 27.1. typical c2 pin shar ing............. ................ ................. ................ ......... 320 www.datasheet.in
rev. 1.0 11 c8051f99x-c8051f98x list of tables table 2.1. product selecti on guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 table 3.1. pin definitions for the c8051f99x-c8051f98x . . . . . . . . . . . . . . . . . . . 32 table 3.2. qfn-20 package di mensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 table 3.3. pcb land pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 table 3.4. qfn-24 package di mensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 table 3.5. pcb land pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 table 3.6. qsop-24 package dimensi ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 table 3.7. pcb land pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 table 4.1. absolute maximum rati ngs ................... .............. ............... ........... ......... 46 table 4.2. global electrical char acteristics ............ .............. ............... ........... ......... 47 table 4.3. port i/ o dc electrical char acteristics ......... ................. ................ ........... 52 table 4.4. reset electric al characteristics ...... ................. .............. .............. ........... 55 table 4.5. power managem ent electrical specifications .... .............. .............. ......... 56 table 4.6. flash electrical char acteristics ...... ................. .............. .............. ........... 56 table 4.7. internal precision o scillator electrical characteri stics ........... ................ 56 table 4.8. internal low-power oscillator electrical characteri stics ........... ............. 56 table 4.9. smartclock characterist ics ............. .............. .............. .............. ........... 57 table 4.10. adc0 electric al characteristics ....... .............. .............. .............. ........... 57 table 4.11. temperature sensor electrical char acteristics ............. .............. ......... 58 table 4.12. voltage reference elec trical characteristics ....... ............ ........... ......... 59 table 4.13. iref0 electrical char acteristics .......... .............. ............... ........... ......... 60 table 4.14. comparator electrical characteristics .... ................ ................. ............. 61 table 4.15. vreg0 electric al characteristics .... .............. .............. .............. ........... 62 table 4.16. capacitive sense elec trical characteristi cs .............. ................ ........... 63 table 5.1. representative conversion times and energy consumption for the sar adc with 1.65 v high-spe ed vref . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 table 8.1. operati on with auto-scan and accumulate . . . . . . . . . . . . . . . . . . . . . 103 table 9.1. cip-51 instruct ion set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 table 12.1. special f unction register (sfr) memory m ap (page 0x0) . . . . . . . . 131 table 12.2. special f unction register (sfr) memory m ap (page 0xf) . . . . . . . . 132 table 12.3. special f unction registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 table 13.1. interrupt summar y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 table 14.1. flash security summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 table 15.1. power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 table 16.1. example 16-bit crc out puts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 table 19.1. recommended xfcn settings for crys tal mode . . . . . . . . . . . . . . . . 188 table 19.2. recommended xfcn se ttings for rc and c modes . . . . . . . . . . . . . 189 table 20.1. smartclock internal registers ............. ................ ................. ........... 196 table 20.2. smartclock lo ad capacitance settings . . . . . . . . . . . . . . . . . . . . . 203 table 20.3. smartclock bias settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 table 21.1. port i/o a ssignment for analog functi ons . . . . . . . . . . . . . . . . . . . . . 215 table 21.2. port i/o assi gnment for digital functions . . . . . . . . . . . . . . . . . . . . . . 216 table 21.3. port i/o assignmen t for external digital event capture functions . . 216 www.datasheet.in
c8051f99x-c8051f98x 12 rev. 1.0 table 22.1. smbus clock source sele ction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 table 22.2. minimum sda setup and hold times . . . . . . . . . . . . . . . . . . . . . . . . 239 table 22.3. sources for hardware changes to smb0cn . . . . . . . . . . . . . . . . . . . 243 table 22.4. hardware address recognition ex amples (ehack = 1) . . . . . . . . . . 244 table 22.5. smbus status decoding wi th hardware ack generation disabled (ehack = 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 table 22.6. smbus status decoding wi th hardware ack generation enabled ? (ehack = 1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 table 23.1. timer settings for standard baud rates ? using the internal 24.5 mhz o scillator . . . . . . . . . . . . . . . . . . . . . . . 262 table 23.2. timer settings for standard baud rates ? using an external 22.1184 mhz oscillator . . . . . . . . . . . . . . . . . . . . . 262 table 24.1. spi slave timing paramete rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 table 25.1. timer 0 running modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 table 26.1. pca timebase input opti ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 table 26.2. pca0cpm and pca0 pwm bit settings for pca ? capture/compare modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 table 26.3. watchdog timer timeout in tervals1 . . . . . . . . . . . . . . . . . . . . . . . . . . 310 www.datasheet.in
rev. 1.0 13 c8051f99x-c8051f98x list of registers sfr definition 5.1. adc0cn: adc0 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 sfr definition 5.2. adc0cf: adc0 c onfiguration . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 sfr definition 5.3. adc0 ac: adc0 accumulator configuration . . . . . . . . . . . . . . . . . 74 sfr definition 5.4. adc0 pwr: adc0 burst mode power-up time . . . . . . . . . . . . . . 75 sfr definition 5.5. adc0tk : adc0 burst mode track time . . . . . . . . . . . . . . . . . . . . 76 sfr definition 5.6. adc0h: adc0 data word high byte . . . . . . . . . . . . . . . . . . . . . . 77 sfr definition 5.7. adc0l: adc0 data word low byte . . . . . . . . . . . . . . . . . . . . . . . 77 sfr definition 5.8. adc0gth: a dc0 greater-than high byte . . . . . . . . . . . . . . . . . . 78 sfr definition 5.9. adc0gtl: ad c0 greater-than low byte . . . . . . . . . . . . . . . . . . 78 sfr definition 5.10. adc0lth: ad c0 less-than high byte . . . . . . . . . . . . . . . . . . . 79 sfr definition 5.11. adc0ltl: adc0 less-than low byte . . . . . . . . . . . . . . . . . . . . 79 sfr definition 5.12. adc0mx : adc0 input channel sele ct . . . . . . . . . . . . . . . . . . . . 82 sfr definition 5.13. toffh: adc0 data word high byte . . . . . . . . . . . . . . . . . . . . . 85 sfr definition 5.14. toffl: adc0 data word low byte . . . . . . . . . . . . . . . . . . . . . . 85 sfr definition 5.15. ref0cn : voltage reference contro l . . . . . . . . . . . . . . . . . . . . . 88 sfr definition 6.1. iref0c n: current reference control . . . . . . . . . . . . . . . . . . . . . . 89 sfr definition 6.2. iref0c f: current reference configuration . . . . . . . . . . . . . . . . . 90 sfr definition 7.1. cpt0cn: comparator 0 control . . . . . . . . . . . . . . . . . . . . . . . . . . 94 sfr definition 7.2. cpt0md : comparator 0 mode selection . . . . . . . . . . . . . . . . . . . 95 sfr definition 7.3. cpt0 mx: comparator0 input channel select . . . . . . . . . . . . . . . . 97 sfr definition 8.1. cs0cn: capacit ive sense control . . . . . . . . . . . . . . . . . . . . . . . 106 sfr definition 8.2. cs0cf: capacitive sense confi guration . . . . . . . . . . . . . . . . . . . 107 sfr definition 8.3. cs0dh: capac itive sense data high byte . . . . . . . . . . . . . . . . . 108 sfr definition 8.4. cs0dl: capacitive sense data low byte . . . . . . . . . . . . . . . . . . 108 sfr definition 8.5. cs0scan0 : capacitive sense channel scan mask 0 . . . . . . . . 109 sfr definition 8.6. cs0scan1 : capacitive sense channel scan mask 1 . . . . . . . . 109 sfr definition 8.7. cs0ss: c apacitive sense auto-scan start channel . . . . . . . . . 110 sfr definition 8.8. cs0se: c apacitive sense auto-scan end channel . . . . . . . . . . 110 sfr definition 8.9. cs0thh: capacitive sense comparator threshold high byte . . 111 sfr definition 8.10. cs0thl: capacitive sense comparator threshold low byte . 111 sfr definition 8.11. cs0md1: capacitive sense mo de 1 . . . . . . . . . . . . . . . . . . . . . 112 sfr definition 8.12. cs0md2: capacitive sense mo de 2 . . . . . . . . . . . . . . . . . . . . . 113 sfr definition 8.13. cs0md3: capacitive sense mo de 3 . . . . . . . . . . . . . . . . . . . . . 114 sfr definition 8.14. cs0pm: capacitive sense pin monitor . . . . . . . . . . . . . . . . . . . 115 sfr definition 8.15. cs0mx: capa citive sense mux channel sele ct . . . . . . . . . . . . 117 sfr definition 9.1. dpl: da ta pointer low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 sfr definition 9.2. dph: data pointer high byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 sfr definition 9.3. sp: stack pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 sfr definition 9.4. acc: a ccumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 sfr definition 9.5. b: b regi ster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 sfr definition 9.6. psw: pr ogram status word . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 sfr definition 12.1. sfr page: sfr page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 sfr definition 13.1. ie: inte rrupt enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 www.datasheet.in
c8051f99x-c8051f98x 14 rev. 1.0 sfr definition 13.2. ip: interr upt priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 sfr definition 13.3. eie1: extended interrupt enable 1 . . . . . . . . . . . . . . . . . . . . . . 143 sfr definition 13.4. eip1: extended interrupt priority 1 . . . . . . . . . . . . . . . . . . . . . . 144 sfr definition 13.5. eie2: extended interrupt enable 2 . . . . . . . . . . . . . . . . . . . . . . 145 sfr definition 13.6. eip2: extended interrupt priority 2 . . . . . . . . . . . . . . . . . . . . . . 146 sfr definition 13.7. it01cf: int0 /int1 configuration . . . . . . . . . . . . . . . . . . . . . . . 148 sfr definition 14.1. deviceid: device identification . . . . . . . . . . . . . . . . . . . . . . . . 153 sfr definition 14.2. re vid: revision identif ication . . . . . . . . . . . . . . . . . . . . . . . . . . 154 sfr definition 14.3. psctl: program store r/w control . . . . . . . . . . . . . . . . . . . . . 158 sfr definition 14.4. flkey: flash lock and key . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 sfr definition 14.5. flscl: flash scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 sfr definition 14.6. flwr: flash write only . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 sfr definition 15.1. pmu0cf: powe r management unit configuration 1,2,3 . . . . . . . . . . 166 sfr definition 15.2. pmu0fl : power management unit flag 1,2 . . . . . . . . . . . . . . . . . . . . 167 sfr definition 15.3. pmu0md: powe r management unit mode . . . . . . . . . . . . . . . . 168 sfr definition 15.4. pcon: powe r management control register . . . . . . . . . . . . . . 169 sfr definition 16.1. crc0cn: crc0 c ontrol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 sfr definition 16.2. crc0in: crc0 da ta input . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 sfr definition 16.3. crc0da t: crc0 data output . . . . . . . . . . . . . . . . . . . . . . . . . 174 sfr definition 16.4. crc0 auto: crc0 automatic control . . . . . . . . . . . . . . . . . . . 175 sfr definition 16.5. crc0cnt: crc0 automatic flash sector count . . . . . . . . . . . 176 sfr definition 16.6. crc0flip: crc0 bi t flip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 sfr definition 17.1. reg0cn: volt age regulator control . . . . . . . . . . . . . . . . . . . . 178 sfr definition 18.1. vdm0 cn: vdd supply monitor control . . . . . . . . . . . . . . . . . . 182 sfr definition 18.2. rstsrc: reset source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 sfr definition 19.1. clksel: clock select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 sfr definition 19.2. oscicn: inter nal oscillator control . . . . . . . . . . . . . . . . . . . . . 192 sfr definition 19.3. oscicl: intern al oscillator calibration . . . . . . . . . . . . . . . . . . . 193 sfr definition 19.4. oscxcn: external oscillator c ontrol . . . . . . . . . . . . . . . . . . . . 194 sfr definition 20.1. rtc0key: smartclock lock and key . . . . . . . . . . . . . . . . . . 199 sfr definition 20.2. rtc0 adr: smartclock address . . . . . . . . . . . . . . . . . . . . . . 200 sfr definition 20.3. rtc0da t: smartclock data . . . . . . . . . . . . . . . . . . . . . . . . . 200 internal register definition 20. 4. rtc0cn: smartclock control . . . . . . . . . . . . . . . 209 internal register definition 20.5. rtc0xcn: smartclock oscillator control . . . . . . 210 internal register definition 20.6. rtc0xcf: smartclock o scillator configuration . 211 internal register definition 20.7. capturen: smartclock ti mer capture . . . . . . . 212 internal register definition 20.8. alar mn: smartclock alarm programmed value 212 sfr definition 21.1. xbr0: port i/o crossbar regist er 0 . . . . . . . . . . . . . . . . . . . . . 220 sfr definition 21.2. xbr1: port i/o crossbar regist er 1 . . . . . . . . . . . . . . . . . . . . . 221 sfr definition 21.3. xbr2: port i/o crossbar regist er 2 . . . . . . . . . . . . . . . . . . . . . 222 sfr definition 21.4. p0mask : port0 mask register . . . . . . . . . . . . . . . . . . . . . . . . . 223 sfr definition 21.5. p0mat: port0 ma tch register . . . . . . . . . . . . . . . . . . . . . . . . . . 223 sfr definition 21.6. p1mask : port1 mask register . . . . . . . . . . . . . . . . . . . . . . . . . 224 sfr definition 21.7. p1mat: port1 ma tch register . . . . . . . . . . . . . . . . . . . . . . . . . . 224 sfr definition 21.8. p0: port0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 www.datasheet.in
rev. 1.0 15 c8051f99x-c8051f98x sfr definition 21.9. p0ski p: port0 skip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 sfr definition 21.10. p0mdin : port0 input mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 sfr definition 21.11. p0mdout: port 0 output mode . . . . . . . . . . . . . . . . . . . . . . . . 227 sfr definition 21.12. p0drv: port0 drive strength . . . . . . . . . . . . . . . . . . . . . . . . . 228 sfr definition 21.13. p1: port1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 sfr definition 21.14. p1 skip: port1 skip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 sfr definition 21.15. p1mdin : port1 input mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 sfr definition 21.16. p1mdout: port 1 output mode . . . . . . . . . . . . . . . . . . . . . . . . 230 sfr definition 21.17. p1drv: port1 drive strength . . . . . . . . . . . . . . . . . . . . . . . . . 231 sfr definition 21.18. p2: port2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 sfr definition 21.19. p2mdout: port 2 output mode . . . . . . . . . . . . . . . . . . . . . . . . 232 sfr definition 21.20. p2drv: port2 drive strength . . . . . . . . . . . . . . . . . . . . . . . . . 232 sfr definition 22.1. smb0cf: smbu s clock/configuration . . . . . . . . . . . . . . . . . . . 240 sfr definition 22.2. smb0cn : smbus control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 sfr definition 22.3. smb0a dr: smbus slave address . . . . . . . . . . . . . . . . . . . . . . 245 sfr definition 22.4. smb0adm: sm bus slave address mask . . . . . . . . . . . . . . . . . 245 sfr definition 22.5. smb0dat: smbus data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 sfr definition 23.1. scon0: serial port 0 control . . . . . . . . . . . . . . . . . . . . . . . . . . 260 sfr definition 23.2. sbuf0: serial (uart0) port data buffer . . . . . . . . . . . . . . . . . 261 sfr definition 24.1. spi0cf g: spi0 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 270 sfr definition 24.2. spi0cn: spi0 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 sfr definition 24.3. spi0ck r: spi0 clock rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 sfr definition 24.4. spi0dat: spi0 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 sfr definition 25.1. ckcon: clock control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 sfr definition 25.2. tcon: timer cont rol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 sfr definition 25.3. tmod: ti mer mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 sfr definition 25.4. tl0: timer 0 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 sfr definition 25.5. tl1: timer 1 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 sfr definition 25.6. th0: timer 0 hi gh byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 sfr definition 25.7. th1: timer 1 hi gh byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 sfr definition 25.8. tmr2cn: timer 2 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 sfr definition 25.9. tmr2rll: ti mer 2 reload register low byte . . . . . . . . . . . . . 290 sfr definition 25.10. tmr2 rlh: timer 2 reload re gister high byte . . . . . . . . . . . 290 sfr definition 25.11. tmr2l: timer 2 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 sfr definition 25.12. tmr2h timer 2 high byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 sfr definition 25.13. tmr3cn: timer 3 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 sfr definition 25.14. tmr3 rll: timer 3 reload regi ster low byte . . . . . . . . . . . . 296 sfr definition 25.15. tmr3 rlh: timer 3 reload re gister high byte . . . . . . . . . . . 296 sfr definition 25.16. tmr3l: timer 3 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 sfr definition 25.17. tmr3h timer 3 high byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 sfr definition 26.1. pca0cn: pca control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 sfr definition 26.2. pca0md: pca mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 sfr definition 26.3. pca0pwm: pc a pwm configuration . . . . . . . . . . . . . . . . . . . . 313 sfr definition 26.4. pc a0cpmn: pca capture/compare mode . . . . . . . . . . . . . . . 314 sfr definition 26.5. pca0l: pca counter/timer low byte . . . . . . . . . . . . . . . . . . . 315 www.datasheet.in
c8051f99x-c8051f98x 16 rev. 1.0 sfr definition 26.6. pca0h: pca counter/timer high byte . . . . . . . . . . . . . . . . . . . 315 sfr definition 26.7. pca0cpln: pca capture module low byte . . . . . . . . . . . . . . . 316 sfr definition 26.8. pca0cphn: pca capture module high byte . . . . . . . . . . . . . . 316 c2 register definition 27.1. c2add: c2 address . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 c2 register definition 27.2. device id: c2 device id . . . . . . . . . . . . . . . . . . . . . . . . 318 c2 register definition 27.3. revid: c2 revision id . . . . . . . . . . . . . . . . . . . . . . . . . 318 c2 register definition 27.4. fp ctl: c2 flash programming cont rol . . . . . . . . . . . . 319 c2 register definition 27.5. fp dat: c2 flash programming data . . . . . . . . . . . . . . 319 www.datasheet.in
rev. 1.0 17 c8051f99x-c8051f98x 1. system overview c8051f99x-c8051f98x devices are fully integrated mixed-signal system-on-a-chip mcus. highlighted features are listed below. refer to ta b l e 2.1 for specific product feature selection and part ordering numbers. ? ultra low power consumption in active and sleep modes. ? high-speed pipelined 8051-compatible microcontroller core (up to 25 mips) ? in-system, full-speed, non-intrusive debug interface (on-chip) ? 10-bit 300 ksps or 12-bit 75 ksps single-ended adc with analog multiplexer ? 6-bit programmable current reference (resolution can be increased with pwm) ? precision programmable 24.5 mhz internal oscillator with spread spectrum technology. ? 8 kb , 4 kb, or 2 kb of on-chip flash memory ? 512 bytes of on-chip ram ? smbus/i 2 c, enhanced uart, and enhanced spi seri al interfaces implemented in hardware ? four general-purpose 16-bit timers ? programmable counter/timer array (pca) with three capture/compare modules and watchdog timer function ? on-chip power-on reset, v dd monitor, and temperature sensor ? one on-chip voltage comparator ? up to 14 capacitive touch (quicksense?) inputs ? up to 17 port i/o with on-chip power-on reset, v dd monitor, watchdog timer, and clock oscillator, the c8051f99x- c8051f98x devices are truly stand-alone system-on -a-chip solutions. the flash memory can be reprogrammed even in-circuit, providing non-volatile da ta storage, and also allowing field upgrades of the 8051 firmware. user software has complete control of all peripherals, and may individually shut down any or all peripherals for power savings. the on-chip silicon labs 2- wire (c2) development interface allo ws non-intrusive (uses no on-chip resources), full speed, in-circuit debugging using the production mcu installed in the final application. this debug logic supports inspection and modification of memory and registers, setting breakpoints, single stepping, run and halt commands. all analog and digita l peripherals are fully functional while debugging using c2. the two c2 interface pins can be shared with user functions, a llowing in-system debugging without occupying package pins. each device is specified for 1.8 to 3.6 v operation over the industrial temperature range (?40 to +85 c). the port i/o and rst pins are powered from the supply voltage. the c8051f99x-c8051f98x devices are available in 20-pin or 24-pin qfn or 24-pin qsop packages. all package options are lead-free and rohs compliant. see table 2.1 for ordering information. block diagrams are included in figure 1.1 through figure 1.9 . www.datasheet.in
c8051f99x-c8051f98x 18 rev. 1.0 figure 1.1. C8051F980 block diagram figure 1.2. c8051f981 block diagram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0/vref p0.1/agnd p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6/cnvstr p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake 12-bit adc a m u x temp sensor external vref internal vref vdd xtal2 low power 20 mhz oscillator 6-bit iref vref gnd iref0 cp0 xtal3 xtal4 vreg digital power crc engine port 2 drivers p2.7/c2d p1.0 p1.1 gnd gnd p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.5 p1.6/xtal3 p1.7/xtal4 smartclock oscillator port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6 p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake xtal2 low power 20 mhz oscillator 6-bit iref iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine port 2 drivers p2.7/c2d p1.0 p1.1 gnd p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.5 p1.6/xtal3 p1.7/xtal4 www.datasheet.in
rev. 1.0 19 c8051f99x-c8051f98x figure 1.3. c8051f982 block diagram figure 1.4. c8051f983 block diagram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0/vref p0.1/agnd p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6/cnvstr p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 4 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake 10-bit adc a m u x temp sensor external vref internal vref vdd xtal2 low power 20 mhz oscillator 6-bit iref vref gnd iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine port 2 drivers p2.7/c2d p1.0 p1.1 gnd p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.5 p1.6/xtal3 p1.7/xtal4 port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6 p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 4 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake xtal2 low power 20 mhz oscillator 6-bit iref iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine port 2 drivers p2.7/c2d p1.0 p1.1 gnd p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.5 p1.6/xtal3 p1.7/xtal4 www.datasheet.in
c8051f99x-c8051f98x 20 rev. 1.0 figure 1.5. c8051f985 block diagram figure 1.6. c8051f986 block diagram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6 p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 2 kb isp flash program memory 256 byte sram sfr bus port 1 drivers p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.5 spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake xtal2 low power 20 mhz oscillator 6-bit iref gnd p1.6/xtal3 iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine p1.7/xtal4 port 2 drivers p2.7/c2d p1.0 p1.1 256 byte xram gnd port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0/vref p0.1/agnd p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6/cnvstr p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.4 p1.5 spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake 12-bit adc a m u x temp sensor external vref internal vref vdd xtal2 low power 20 mhz oscillator 6-bit iref vref gnd p1.6/xtal3 iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine p1.7/xtal4 port 2 drivers p2.7/c2d p1.0 p1.1 www.datasheet.in
rev. 1.0 21 c8051f99x-c8051f98x figure 1.7. c8051f987 block diagram figure 1.8. c8051f988 block diagram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6 p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus port 1 drivers p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.4 p1.5 spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake xtal2 low power 20 mhz oscillator 6-bit iref gnd p1.6/xtal3 iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine p1.7/xtal4 port 2 drivers p2.7/c2d p1.0 p1.1 256 byte xram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0/vref p0.1/agnd p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6/cnvstr p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 4 kb isp flash program memory 256 byte sram sfr bus port 1 drivers p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.4 p1.5 spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake 10-bit adc a m u x temp sensor external vref internal vref vdd xtal2 low power 20 mhz oscillator 6-bit iref vref gnd p1.6/xtal3 iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine p1.7/xtal4 port 2 drivers p2.7/c2d p1.0 p1.1 www.datasheet.in
c8051f99x-c8051f98x 22 rev. 1.0 figure 1.9. c8051f989 block diagram figure 1.10. c8051f990 block diagram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6 p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 4 kb isp flash program memory 256 byte sram sfr bus port 1 drivers p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.4 p1.5 spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake xtal2 low power 20 mhz oscillator 6-bit iref gnd p1.6/xtal3 iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine p1.7/xtal4 port 2 drivers p2.7/c2d p1.0 p1.1 port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0/vref p0.1/agnd p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6/cnvstr p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers 13-channel capacitance to digital converter spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake 12-bit adc a m u x temp sensor external vref internal vref vdd xtal2 low power 20 mhz oscillator 6-bit iref vref gnd iref0 cp0 xtal3 xtal4 vreg digital power crc engine port 2 drivers p2.7/c2d p1.0 p1.1 gnd gnd p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.5 p1.6/xtal3 p1.7/xtal4 smartclock oscillator www.datasheet.in
rev. 1.0 23 c8051f99x-c8051f98x figure 1.11. c8051f991 block diagram figure 1.12. c8051f996 block diagram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6 p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers 13-channel capacitance to digital converter spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake xtal2 low power 20 mhz oscillator 6-bit iref iref0 cp0 xtal3 xtal4 vreg digital power crc engine port 2 drivers p2.7/c2d p1.0 p1.1 gnd gnd p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.5 p1.6/xtal3 p1.7/xtal4 smartclock oscillator port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0/vref p0.1/agnd p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6/cnvstr p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.4 p1.5 14-channel capacitance to digital converter spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake 12-bit adc a m u x temp sensor external vref internal vref vdd xtal2 low power 20 mhz oscillator 6-bit iref vref gnd p1.6/xtal3 iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine p1.7/xtal4 port 2 drivers p2.7/c2d p1.0 p1.1 www.datasheet.in
c8051f99x-c8051f98x 24 rev. 1.0 figure 1.13. c8051f997 block diagram port 0 drivers digital peripherals uart timers 0, 1, 2, 3 pca/ wdt smbus priority crossbar decoder p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4/tx p0.5/rx p0.6 p0.7/iref0 crossbar control port i/o configuration cip-51 8051 controller core 8 kb isp flash program memory 256 byte sram sfr bus 256 byte xram port 1 drivers p1.0/cp0+ p1.1/cp0- p1.2 p1.3 p1.4 p1.5 14-channel capacitance to digital converter spi analog peripherals comparator + - vdd xtal1 sysclk system clock configuration external oscillator circuit precision 24.5 mhz oscillator debug / programming hardware power on reset/pmu reset c2d c2ck/rst wake xtal2 low power 20 mhz oscillator 6-bit iref p1.6/xtal3 iref0 cp0 smartclock oscillator xtal3 xtal4 gnd vreg digital power crc engine p1.7/xtal4 port 2 drivers p2.7/c2d p1.0 p1.1 www.datasheet.in
rev. 1.0 25 c8051f99x-c8051f98x 1.1. cip-51? microcontroller core 1.1.1. fully 8051 compatible the c8051f99x-c8051f98x family utiliz es silicon labs' proprietary cip-51 microcontroller core. the cip- 51 is fully compatible with the mc s-51? instruction set; standard 803x/805x assemblers and compilers can be used to develop software. the cip-51 core offers all the peripherals included with a standard 8052. 1.1.2. improved throughput the cip-51 employs a pipelined architecture that greatly increases its instruction throughput over the standard 8051 architecture. in a standard 8051, all instructions except for mul and div take 12 or 24 system clock cycles to execute with a maximum system clock of 12-to-24 mhz. by contrast, the cip-51 core executes 70% of its instructions in one or two sy stem clock cycles, with only four instructions taking more than four system clock cycles. the cip-51 has a total of 109 instructions. the table below shows the total number of instructions that require each execution time. with the cip-51's maximum system clock at 25 mhz, it has a peak throughput of 25 mips. 1.1.3. additional features the c8051f99x-c8051f98x soc family includes several key enhancements to the cip-51 core and peripherals to improve performance and ease of use in end applications. the extended interrupt handler provides multiple interrupt sources into t he cip-51 allowing numerous analog and digital peripherals to interrupt the cont roller. an interrupt driv en system requires less intervention by the mcu, giving it more effective throughput. the extra interrupt sources are very useful when building multi-task ing, real-time systems. eight reset sources are available: power-on reset circuitry (por), an on-chip v dd monitor (forces reset when power supply voltage drops below safe leve ls), a watchdog timer, a missing clock detector, smartclock oscillator fail or alarm, a voltage level det ection from comparator0, a forced software reset, an external reset pin, and an illegal flash access protection circuit. each reset source exce pt for the por, reset input pin, or flash error may be disabled by the user in software. the wdt may be permanently disabled in software after a powe r-on reset during mcu initialization. the internal oscillator fa ctory calibra ted to 24.5 mhz and is accurate to 2% over the full temperature and supply range. the internal oscillator period can also be adjusted by user fi rmware. an ad ditional 20 mhz low power oscillator is also available which facilitat es low-power operation. an external oscillator drive circuit is included, allowing an external crystal, cerami c resonator, capacitor, rc, or cmos clock source to generate the system clock. if desired, the system cloc k source may be switched on-the-fly between both internal and external oscillator circ uits. an external oscilla tor can also be extremely useful in low power applications, allowing the mcu to run from a slow (pow er saving) source, while pe riodically switching to the fast (up to 25 mhz) internal oscillator as needed. clocks to execute 1 2 2/3 3 3/4 4 4/5 5 8 number of instructions 26 50 5 14 7 3 1 2 1 www.datasheet.in
c8051f99x-c8051f98x 26 rev. 1.0 1.2. port input/output digital and analog resources are available through 16 or 17 i/o pins. port pins are organized as three byte- wide ports. port pins p0.0?p1.7 can be defined as digita l or analog i/o. digital i/o pins can be assigned to one of the internal digital resources or used as ge neral purpose i/o (gpio). analog i/o pins are used by the internal analog resources. p2.7 can be used as gpio and is shared with the c2 interface data signal (c2d). see section ?27. c2 interface? on page 317 for more details. the designer has complete control over which digital and analog functions are as signed to individual port pins, limited only by the nu mber of physical i/o pins. this resour ce assignment flexibility is achieved through the use of a priority crossbar decoder. see section ?21.3. priority crossbar decoder? on page 217 for more information on the crossbar. all port i/os can tolerate voltages up to the supply rail when used as digital inputs or open-drain outputs. for port i/os configured as push-pull outputs, current is sourced from the vdd supply. port i/os used for analog functions can operate up to the vdd supply voltage. see section ?21.1. port i/o modes of operation? on page 214 for more information on port i/o operati ng modes and the electrical specifications chapter for detailed electrical specifications. figure 1.14. port i/o functional block diagram xbr0, xbr1, xbr2, pnskip registers digital crossbar priority decoder 2 p0 i/o cells p0.0 p0.7 8 port match p0mask, p0mat p1mask, p1mat uart (internal digital signals) highest priority lowest priority sysclk 2 smbus t0, t1 2 4 pca 4 cp0 output spi0 4 p1 i/o cells p1.0 p1.7* 8 (port latches) p0 (p0.0-p0.7) (p1.0-p1.7) 8 8 p1 p2 i/o cell p2 (p2.7) 1 1 pnmdout, pnmdin registers p2.7 to analog peripherals (adc0, cp0, and cp1 inputs, vref, iref0, agnd) external interrupts ex0 and ex1 *p1.5 is not available on 20-pin devices. www.datasheet.in
rev. 1.0 27 c8051f99x-c8051f98x 1.3. serial ports the c8051f99x-c8051f98x family includes an smbus/i 2 c interface, a full-duplex uart with enhanced baud rate configuration, and an enhanced spi interface. each of the serial buses is fully implemented in hardware and makes extensive use of the cip-51's inte rrupts, thus requiring very little cpu intervention. 1.4. programmable counter array an on-chip programmable counter/timer array (pca) is included in addition to the four 16-bit general purpose counter/timers. the pca consists of a dedicated 16-bit counter/timer time base with three programmable capture/compare modules. the pca clo ck is derived from one of seven sources: the system clock divided by 12, the system clock divided by 4, timer 0 overflows, an external clock input (eci), the system clock, th e external oscillator clock source divided by 8, or the smartclock divided by 8. each capture/compare module can be configured to oper ate in a variety of modes: edge-triggered capture, software timer, high-speed output, pulse width modulator (8, 9, 10, 11, or 16-bit), or frequency output. additionally, capture/compare module 2 offers watchd og timer (wdt) capabilit ies. following a system reset, module 2is configured and enabled in wdt mode. the pca capture/compare module i/o and external clock input may be routed to port i/o via the digital crossbar. figure 1.15. pca block diagram capture /compare module 1 capture /compare module 0 cex1 eci crossbar cex0 p ort i/o 16 -bit counter/timer pca clock mux sysclk/12 sysclk/4 timer 0 overflow e c i sysclk external clock/8 smartclock/8 capture / compare module 2 / w dt cex2 www.datasheet.in
c8051f99x-c8051f98x 28 rev. 1.0 1.5. sar adc with 16-bit auto-averag ing accumulator and autonomous low power burst mode c8051f99x-c8051f98x devices have a 300 ksps, 10-bit or 75 ksps 12-bit successive-approximation- register (sar) adc with integrated track-and-hold an d programmable window detector. adc0 also has an autonomous low power burst mode which can automatically enable adc0, capture and accumulate samples, then place adc0 in a low power shutdown mode without cpu intervention. it also has a 16-bit accumulator that can automatically average the adc re sults, providing an effective 11, 12, or 13 bit adc result without any additional cpu intervention. the adc can sample the voltage at select gpio pins (see figure 1.17 ) and has an on-chip attenuator that allows it to measure voltages up to twice the voltage reference. additi onal adc inputs include an on-chip temperature sensor, the vdd supply voltage, and the internal digital supply voltage. figure 1.16. adc0 functional block diagram adc0cf amp0gn ad0tm ad08be ad0sc0 ad0sc1 ad0sc2 ad0sc3 ad0sc4 10/12-bit sar adc ref sysclk adc0h 32 adc0cn ad0cm0 ad0cm1 ad0cm2 ad0wint ad0busy ad0int bursten ad0en timer 0 overflow timer 2 overflow timer 3 overflow start conversion 000 ad0busy (w) vdd adc0lth ad0wint 001 010 011 100 cnvstr input window compare logic adc0ltl adc0gth adc0gtl adc0l ain+ from amux0 burst mode logic adc0tk adc0pwr 16-bit accumulator www.datasheet.in
rev. 1.0 29 c8051f99x-c8051f98x figure 1.17. adc0 multiplexer block diagram 1.6. programmable current reference (iref0) c8051f99x-c8051f98x devices include an on-chip prog rammable current reference (source or sink) with two output current settings: low power mode and high current mode. the maximum current output in low power mode is 63 a (1 a steps) and the maximum current ou tput in high current mode is 504 a (8 a steps). 1.7. comparator c8051f99x-c8051f98x devices include an on-chip programmable voltage comparator: comparator 0 (cpt0) which is shown in figure 1.18 . the comparator offers programmable response time a nd hysteresis, an analog in put multiplexer, and two outputs that are optionally available at the port pins: a synchronous ?latched? output (cp0), or an asynchronous ?raw? output (cp0a) . the asynchronous cp0a signal is available even when the system clock is not active. this allows the comparator to op erate and generate an output when the device is in some low po wer modes. the comparator inputs may be connected to port i/o pins or to other internal signals. port pins may also be used to directly sense capacitive touch switches. s ee application note an338 for details on capacitive touch switch sensing. adc0 temp sensor amux adc0mx ad0mx4 ad0mx3 ad0mx2 ad0mx1 am0mx0 ain+ p0.1 digital supply vdd programmable attenuator gain = 0.5 or 1 p1.2 p0.7 p0.5 p0.4 p0.3 p0.2 p0.6 *p1.4 p1.3 *only available on 24-pin devices. www.datasheet.in
c8051f99x-c8051f98x 30 rev. 1.0 figure 1.18. comparator 0 functional block diagram vdd cpt0cn reset decision tree + - crossbar interrupt logic q q set clr d q q set clr d (synchronizer) gnd cp0 + px.x cp0en cp0out cp0rif cp0fif cp0hyp1 cp0hyp0 cp0hyn1 cp0hyn0 cpt0md cp0rie cp0fie cp0md1 cp0md0 cp0 cp0a cp0 rising-edge cp0 falling-edge cp0 interrupt px.x px.x px.x cp0 - (asynchronous) analog input multiplexer www.datasheet.in
rev. 1.0 31 c8051f99x-c8051f98x 2. ordering information table 2.1. product selection guide ordering part number mips (peak) flash memory (kb) ram (bytes) smartclock real time clock smbus/i 2 c, uart, enhanced spi timers (16-bit) programmable counter array digital port i/os analog to digital converter inputs adc with internal voltage reference and temperature sensor capacitive touch (quicksense?) inputs programmable current reference analog comparators lead-free (rohs compliant) package C8051F980-gm 25 8 512 ? ? 4 ? 16 9 12-bit ? ? 1 ? qfn-20 c8051f981-gm 25 8 512 ? ? 4 ? 16 ? ? ? ? 1 ? qfn-20 c8051f982-gm 25 4 512 ? ? 4 ? 16 9 10-bit ? ? 1 ? qfn-20 c8051f983-gm 25 4 512 ? ? 4 ? 16 ? ? ? ? 1 ? qfn-20 c8051f985-gm 25 2 512 ? ? 4 ? 16 ? ? ? ? 1 ? qfn-20 c8051f986-gm 25 8 512 ? ? 4 ? 17 10 12-bit ? ? 1 ? qfn-24 c8051f986-gu 25 8 512 ? ? 4 ? 17 10 12-bit ? ? 1 ? qsop-24 c8051f987-gm 25 8 512 ? ? 4 ? 17 ? ? ? ? 1 ? qfn-24 c8051f987-gu 25 8 512 ? ? 4 ? 17 ? ? ? ? 1 ? qsop-24 c8051f988-gm 25 4 512 ? ? 4 ? 17 10 10-bit ? ? 1 ? qfn-24 c8051f988-gu 25 4 512 ? ? 4 ? 17 10 10-bit ? ? 1 ? qsop-24 c8051f989-gm 25 4 512 ? ? 4 ? 17 ? ? ? ? 1 ? qfn-24 c8051f989-gu 25 4 512 ? ? 4 ? 17 ? ? ? ? 1 ? qsop-24 c8051f990-gm 25 8 512 ? ? 4 ? 16 9 12-bit 13 ? 1 ? qfn-20 c8051f991-gm 25 8 512 ? ? 4 ? 16 ? ? 13 ? 1 ? qfn-20 c8051f996-gm 25 8 512 ? ? 4 ? 17 10 12-bit 14 ? 1 ? qfn-24 c8051f996-gu 25 8 512 ? ? 4 ? 17 10 12-bit 14 ? 1 ? qsop-24 c8051f997-gm 25 8 512 ? ? 4 ? 17 ? ? 14 ? 1 ? qfn-24 c8051f997-gu 25 8 512 ? ? 4 ? 17 ? ? 14 ? 1 ? qsop-24 www.datasheet.in
c8051f99x-c8051f98x 32 rev. 1.0 3. pinout and package definitions table 3.1. pin definitions for the c8051f99x-c8051f98x name pin numbers type description ?f980/1/2 ?f983/5 ?f990/1 -gm ?f986/7 ?f988/9 ?f996/7 -gm ?f986/7 ?f988/9 ?f996/7 -gu v dd 4 3 6 p in power supply voltage. must be 1.8 to 3.6 v. gnd 3, 12 2 5 g required ground. rst / c2ck 5 6 9 d i/o d i/o device reset. open-drain output of internal por or v dd monitor. an external source can initiate a system reset by driving this pin low for at least 15 s. a 1 k ? to 5 k ? pullup to v dd is recommended. see section ?18. reset sources? on page 179 section for a complete description. clock signal for the c2 debug interface. p2.7/ c2d 6 7 10 d i/o d i/o port 2.7. this pin can only be used as gpio. the crossbar cannot route signals to this pin and it cannot be configured as an analog input. see port i/o section for a complete description. bi-directional data signal for the c2 debug interface. p1.6/ xtal3 8 9 12 d i/o a in port 1.6. see port i/o section for a complete description. smartclock oscilla tor crystal input. see section 20 for a complete description. p1.7/ xtal4 7 8 11 d i/o a out port 1.7. see port i/o section for a complete description. smartclock oscillator crystal output. see section 20 for a complete description. p0.0/ v ref * 2 24 3 d i/o or a in a in port 0.0. see port i/o section for a complete description. external v ref input. see section ?5.9. voltage and ground reference options? on page 86 . *note: available only on the C8051F980/2/6/8 and c8051f990/6 devices. www.datasheet.in
rev. 1.0 33 c8051f99x-c8051f98x p0.1/ agnd* 1 23 2 d i/o or a in g port 0.1. see port i/o section for a complete description. optional analog ground. see section ?5.9. voltage and ground reference options? on page 86 . p0.2/ xtal1/ rtcout 20 22 1 d i/o or a in a in d out port 0.2. see port i/o section for a complete description. external clock input. this pi n is the external oscillator return for a crystal or resonator. see section ?19. clocking sources? on page 186 . buffered smartclock oscillator output. p0.3/ xtal2/ wakeout 19 21 24 d i/o or a in a out d in a in d out port 0.3. see section ?21. port input/output? on page 213 for a complete description. external clock output. this pin is the excitation driver for an external crystal or resonator. external clock input. this pi n is the external clock input in external cmos clock mode. external clock input. this pi n is the external clock input in capacitor or rc o scillator configurations. see section ?19. clocking sources? on page 186 for complete details. wake-up request signal to wake up external devices. p0.4/ tx 18 20 23 d i/o or a in d out port 0.4. see section ?21. port input/output? on page 213 for a complete description. uart tx pin. see section ?21. port input/ output? on page 213 . p0.5/ rx 17 19 22 d i/o or a in d in port 0.5. see section ?21. port input/output? on page 213 for a complete description. uart rx pin. see section ?21. port input/output? on page 213 . table 3.1. pin definitions for the c8051f99x-c8051f98x (continued) name pin numbers type description ?f980/1/2 ?f983/5 ?f990/1 -gm ?f986/7 ?f988/9 ?f996/7 -gm ?f986/7 ?f988/9 ?f996/7 -gu *note: available only on the C8051F980/2/6/8 and c8051f990/6 devices. www.datasheet.in
c8051f99x-c8051f98x 34 rev. 1.0 p0.6/ cnvstr* 16 18 21 d i/o or a in d in port 0.6. see section ?21. port input/output? on page 213 for a complete description. external convert start input for adc0. see section ?5.7. adc0 analog multiplexer? on page 81 for a complete description. p0.7/ iref0 15 17 20 d i/o or a in a out port 0.7. see section ?21. port input/output? on page 213 for a complete description. iref0 output. see iref section for complete description. p1.0 cp0+ 14 16 19 d i/o or a in a in port 1.0. see section ?21. port input/output? on page 213 for a complete descripti on. may also be used as sck for spi1. comparator0 positive input. see comparator section for complete description. p1.1 cp0- 13 15 18 d i/o or a in a in port 1.1. see section ?21. port input/output? on page 213 for a complete description. comparator0 negative input. see comparator section for complete description. p1.2 11 14 17 d i/o or a in port 1.2. see section ?21. port input/output? on page 213 for a complete description. p1.3 10 13 16 d i/o or a in port 1.3. see section ?21. port input/output? on page 213 for a complete description. p1.4 ? 12 15 d i/o or a in port 1.4. see section ?21. port input/output? on page 213 for a complete description. p1.5 9 11 14 d i/o or a in port 1.5. see section ?21. port input/output? on page 213 for a complete description. table 3.1. pin definitions for the c8051f99x-c8051f98x (continued) name pin numbers type description ?f980/1/2 ?f983/5 ?f990/1 -gm ?f986/7 ?f988/9 ?f996/7 -gm ?f986/7 ?f988/9 ?f996/7 -gu *note: available only on the C8051F980/2/6/8 and c8051f990/6 devices. www.datasheet.in
rev. 1.0 35 c8051f99x-c8051f98x figure 3.1. qfn-20 pinout diagram (top view) 6 p 2 . 7 / c 2 d p1.7/xtal4 p1.6/xtal3 p1.5 p1.3 10 8 7 9 gnd vdd rst/c2ck 4 5 2 1 3 p0.5/rx p0.4/tx p0.3/xtal2/wakeout p0.2/xtal1/rtcout p0.0/vref* 18 19 20 17 p 1 . 2 p1.1/cp0- p1.0/cp0+ p0.7/iref0 p 0 .6 / c n v s t r * 13 12 15 14 C8051F980/1/2/3/5 c8051f990/1 -gm top view gnd (optional connection) p 0 . 1 / a g n d * 16 11 gnd * note: signal only available on ?f980, ?f982 and ?f990 devices. www.datasheet.in
c8051f99x-c8051f98x 36 rev. 1.0 figure 3.2. qfn-24 pinout diagram (top view) p2.7/c2d p1.7/xtal4 p1.6/xtal3 n.c. p1.5 p1.4 10 11 12 8 7 9 n.c. gnd vdd n.c. n.c. rst/c2ck 4 5 6 2 1 3 p0.5/rx p0.4/tx p0.3/xtal2/wakeout p0.2/xtal1/rtcout p0.1/agnd* p0.0/vref* 22 23 24 20 19 21 c8051f986/7/8/9 c8051f996/7 -gm top view gnd (optional connection) p1.3 p1.2 p1.1/cp0- p1.0/cp0+ p0.7/iref0 p0.6/cnvstr* 15 14 13 17 18 16 * note: signal only available on ?f986, ?f988, and ?f996 devices. www.datasheet.in
rev. 1.0 37 c8051f99x-c8051f98x figure 3.3. qsop-24 pinout diagram (top view) p0.2/xtal1/rtcout p0.3/xtal2/wakeout p0.4/tx p0.5/rx p0.6/cnvstr* p0.7/iref0 p1.0/cp0+ p1.1/cp0- p1.2 p1.3 c8051f986/7/8/9, c8051f996/7 - gu p0.1/agnd* p0.0/vref* gnd vdd n.c. n.c. p2.7/c2d p1.4 1 2 3 4 5 6 7 8 9 10 24 23 22 21 20 19 18 17 16 15 p1.7/xtal4 p1.6/xtal3 11 12 p1.5 n.c. 14 13 n.c. rst/c2ck * note: signal only available on ?f986, ?f988, and ?f996 devices. www.datasheet.in
c8051f99x-c8051f98x 38 rev. 1.0 figure 3.4. qfn-20 package drawing table 3.2. qfn-20 package dimensions dimension min typ max dimension min typ max a 0.50 0.55 0.60 f 2.53 bsc a1 0.00 0.02 0.05 l 0.35 0.40 0.45 b 0.20 0.25 0.30 l1 0.00 ? 0.10 c 0.27 0.32 0.37 aaa ? ? 0.05 d 3.00 bsc bbb ? ? 0.05 d2 1.65 1.70 1.75 ccc ? 0.08 e 0.50 bsc ddd ? ? 0.10 e 3.00 bsc eee ? ? 0.10 e2 1.65 1.70 1.75 notes: 1. all dimensions shown are in millim eters (mm) unless otherwise noted. 2. dimensioning and tolerancing per ansi y14.5m-1994. ? www.datasheet.in
rev. 1.0 39 c8051f99x-c8051f98x figure 3.5. typical qfn-20 landing diagram ? www.datasheet.in
c8051f99x-c8051f98x 40 rev. 1.0 table 3.3. pcb land pattern dimension min max d 2.71 ref d2 1.60 1.80 e 0.50 bsc e 2.71 ref e2 1.60 1.80 f 2.53 ref gd 2.10 ? ge 2.10 ? w ? 0.34 x ? 0.28 y 0.61 ref ze ? 3.31 zd ? 3.31 notes: general 1. all dimensions shown are in millimeters (mm) unless otherwise noted. 2. dimensioning and tolerancing is per the ansi y14.5m-1994 specification. 3. this land pattern design is based on ipc-sm-782 guidelines. 4. all dimensions shown are at maximum material condition (mmc). least material condition (lmc) is calculated based on a fabrication allowance of 0.05 mm. solder mask design 1. all metal pads are to be non-solder ma sk defined (nsmd). clearance between the solder mask and the metal pad is to be 60 m minimum, all the way around the pad. stencil design 1. a stainless steel, laser-cut and electro-polished stencil with trapezoidal walls should be used to assure good solder paste release. 2. the stencil thickness should be 0.125 mm (5 mils). 3. the ratio of stencil aperture to land pad size should be 1:1 for all perimeter pads. 4. a 1.45 x 1.45 mm square aperture should be used for the center pad. this provides approximately 70% solder paste coverage on the pad, which is optimum to assure correct component stand-off. card assembly 1. a no-clean, type-3 solder paste is recommended. 2. the recommended card reflow profile is per the jedec/ipc j-std-020 specification for small body components. www.datasheet.in
rev. 1.0 41 c8051f99x-c8051f98x figure 3.6. qfn-24 package drawing table 3.4. qfn-24 package dimensions dimension min typ max dimension min typ max a 0.70 0.75 0.80 l 0.30 0.40 0.50 a1 0.00 0.02 0.05 l1 0.00 ? 0.15 b 0.18 0.25 0.30 aaa ? ? 0.15 d 4.00 bsc bbb ? ? 0.10 d2 2.55 2.70 2.80 ddd ? ? 0.05 e 0.50 bsc eee ? ? 0.08 e 4.00 bsc z ? 0.24 ? e2 2.55 2.70 2.80 y ? 0.18 ? notes: 1. all dimensions shown are in millim eters (mm) unless otherwise noted. 2. dimensioning and tolerancing per ansi y14.5m-1994. 3. this drawing conforms to the jedec solid state outline mo-220, variation wggd except for custom features d2, e2, z, y, and l which are toleranced per supplier designation. 4. recommended card reflow profile is per the jedec/ipc j-std-020 specification for small body components. www.datasheet.in
c8051f99x-c8051f98x 42 rev. 1.0 figure 3.7. typical qfn-24 landing diagram ? www.datasheet.in
rev. 1.0 43 c8051f99x-c8051f98x table 3.5. pcb land pattern dimension min max c1 3.90 4.00 c2 3.90 4.00 e 0.50 bsc x1 0.20 0.30 x2 2.70 2.80 y1 0.65 0.75 y2 2.70 2.80 notes: general 1. all dimensions shown are in millime ters (mm) unless otherwise noted. 2. this land pattern design is based on the ipc-7351 guidelines. solder mask design 1. all metal pads are to be non-solder mask defined (nsmd). clearance between the solder mask and the metal pad is to be 60 m minimum, all the way around the pad. stencil design 1. a stainless steel, laser-cut and electro-polished stencil with trapezoidal walls should be used to assure good solder paste release. 2. the stencil thickness should be 0.125 mm (5 mils). 3. the ratio of stencil aperture to land pad size should be 1:1 for all perimeter pads. 4. a 2x2 array of 1.10 mm x 1.10 mm openings on 1.30 mm pitch should be used for the center ground pad. card assembly 1. a no-clean, type-3 solder paste is recommended. 1. the recommended card reflow profile is per the jedec/ipc j-std-020 specification for small body components. www.datasheet.in
c8051f99x-c8051f98x 44 rev. 1.0 figure 3.8. qsop-24 package diagram table 3.6. qsop-24 package dimensions dimension min typ max dimension min typ max a ? ? 1.75 l 0.40 ? 1.27 a1 0.10 ? 0.25 l2 0.25 bsc b 0.20 ? 0.30 ? 0o ? 8o c 0.10 ? 0.25 aaa 0.20 d 8.65 bsc. bbb 0.18 e 6.00 bsc ccc 0.10 e1 3.90 bsc ddd 0.10 e 0.635 bsc notes: 1. all dimensions shown are in millimeters (mm) unless otherwise noted. 2. dimensioning and tolerancing per ansi y14.5m-1994. 3. this drawing conforms to jedec outline mo-147, variation ae. 4. recommended card reflow profile is per the jede c/ipc j-std-020 specification for small body components. www.datasheet.in
rev. 1.0 45 c8051f99x-c8051f98x figure 3.9. qsop-24 landing diagram table 3.7. pcb land pattern dimension min max c 5.20 5.30 e 0.635 bsc x 0.30 0.40 y 1.50 1.60 notes: general 1. all dimensions shown are in millime ters (mm) unless otherwise noted. 2. this land pattern design is based on the ipc-7351 guidelines. solder mask design 1. all metal pads are to be non-solder mask defined (nsmd). clearance between the solder mask and the metal pad is to be 60 m minimum, all the way around the pad. stencil design 1. a stainless steel, laser-cut and electro-polished stencil with trapezoidal walls should be used to assure good solder paste release. 2. the stencil thickness should be 0.125 mm (5 mils). 3. the ratio of stencil aperture to land pad size should be 1:1 for all perimeter pads. card assembly 1. a no-clean, type-3 solder paste is recommended. 2. the recommended card reflow profile is per the jedec/ipc j-std-020 specification for small body components. ? www.datasheet.in
c8051f99x-c8051f98x 46 rev. 1.0 4. electrical characteristics throughout the electrical characteristics ch apter, ?vdd? refers to the supply voltage. 4.1. absolute maximum specifications table 4.1. absolute maximum ratings parameter conditions min typ max units ambient temperature under bias ?55 ? 125 c storage temperature ?65 ? 150 c voltage on any port i/o pin or rst with respect to gnd ?0.3 ? v dd + 0.3 v voltage on vdd with respect to gnd ?0.3 ? 4.0 v maximum total current through vdd or gnd ?? 500ma maximum current through rst or any port pin ?? 100ma maximum total current through all port pins ?? 200ma note: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of th e devices at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability. www.datasheet.in
rev. 1.0 47 c8051f99x-c8051f98x 4.2. electrical characteristics table 4.2. global electrical characteristics ?40 to +85 c, 25 mhz system clock unless ot herwise specified. see "an358: opti mizing low power operation of the ?f9xx" for details on how to achieve the supply current specifications listed in this table. parameter conditions min typ max units supply voltage (v dd ) 1.8 2.4 3.6 v minimum ram data ? retention voltage 1 not in sleep mode in sleep mode ? ? 1.4 0.3 ? 0.45 v sysclk (system clock) 2 0?25mhz t sysh (sysclk high time) 18 ? ? ns t sysl (sysclk low time) 18 ? ? ns specified operating ? temperature range ?40 ? +85 c digital supply current?cpu active (normal mode, fetching instructions from flash) i dd 3, 4, 5 v dd = 1.8?3.6 v, f = 24.5 mhz (includes precision oscillator current) ?3.64.5 ma v dd = 1.8?3.6 v, f = 20 mhz (includes low power oscillator current) ?3.1 ? ma v dd = 1.8 v, f = 1 mhz v dd = 3.6 v, f = 1 mhz (includes external oscillator/gpio current) ? ? 225 290 ? ? a a v dd = 1.8?3.6 v, f = 32.768 khz (includes smartclock oscillator current) ?84? a i dd frequency ? sensitivity 1, 3, 5 v dd = 1.8?3.6 v, t = 25 c, f < 14 mhz (flash oneshot active, see section 14.6 ) ? 174 ? a/mhz v dd = 1.8?3.6 v, t = 25 c, f > 14 mhz (flash oneshot bypassed, see section 14.6 ) ?88?a/mhz www.datasheet.in
c8051f99x-c8051f98x 48 rev. 1.0 digital supply current?cpu inactive (idle mo de, not fetching instructions from flash) i dd 4, 6 v dd = 1.8?3.6 v, f = 24.5 mhz (includes precision oscillator current) ?1.83.0 ma v dd = 1.8?3.6 v, f = 20 mhz (includes low power oscillator current) ?1.4? ma v dd = 1.8 v, f = 1 mhz v dd = 3.6 v, f = 1 mhz (includes external oscillator/gpio current) ? ? 145 180 ? ? a a v dd = 1.8?3.6 v, f = 32.768 khz (includes smartclock oscillator current) ?82? a i dd frequency sensitivity 1,6 v dd = 1.8?3.6 v, t = 25 c ?67?a/mhz digital supply current?suspend and sleep mode digital supply current ? (suspend mode) v dd = 1.8?3.6 v ?77? a digital supply current ? (sleep mode, smartclock running, 32.768 khz crystal) 1.8 v, t = 25 c 3.0 v, t = 25 c 3.6 v, t = 25 c 1.8 v, t = 85 c 3.0 v, t = 85 c 3.6 v, t = 85 c (includes smartclock oscillator and v bat supply monitor) ? ? ? ? ? ? 0.60 0.70 0.80 0.80 0.90 1.00 ? ? ? ? ? ? a digital supply current ? (sleep mode, smartclock running, internal lfo) 1.8 v, t = 25 c 3.0 v, t = 25 c 3.6 v, t = 25 c 1.8 v, t = 85 c 3.0 v, t = 85 c 3.6 v, t = 85 c (includes smartclock oscillator and v bat supply monitor) ? ? ? ? ? ? 0.30 0.40 0.50 0.50 0.70 0.80 ? ? ? ? ? ? a digital supply current ? (sleep mode) 1.8 v, t = 25 c 3.0 v, t = 25 c 3.6 v, t = 25 c 1.8 v, t = 85 c 3.0 v, t = 85 c 3.6 v, t = 85 c (includes v bat supply monitor) ? ? ? ? ? ? 0.05 0.07 0.08 0.20 0.24 0.28 ? ? ? ? ? ? a digital supply current (sleep mode, vbat supply monitor disabled) 1.8 v, t = 25 c 3.0 v, t = 25 c 3.6 v, t = 25 c 1.8 v, t = 85 c 3.0 v, t = 85 c 3.6 v, t = 85 c ? ? ? ? ? ? 0.005 0.01 0.02 0.15 0.19 0.23 ? ? ? ? ? ? a table 4.2. global electrical characteristics (continued) ?40 to +85 c, 25 mhz system clock unle ss otherwise specified. see "an358: op timizing low power operation of the ?f9xx" for details on how to achieve the supply current specifications listed in this table. parameter conditions min typ max units www.datasheet.in
rev. 1.0 49 c8051f99x-c8051f98x notes: 1. based on device characterization data; not production tested. 2. sysclk must be at least 32 khz to enable debugging. 3. digital supply current depends upon the particular code being executed. the values in this table are obtained with the cpu executing an ?sjmp $? loop, which is the compiled form of a while(1) loop in c. one iteration requires 3 cpu clock cycles, and the flash memory is read on each cycle. the supply current will vary slightly based on the physical location of the sjmp instruction and the number of flash address lines that toggle as a result. in the worst case, current can increase by up to 30% if the sjmp loop straddles a 64-byte flash address boundary (e.g., 0x007f to 0x0080). real-world code with larger loops and longer linear sequences will have few transitions across the 64-byte address boundaries. 4. includes oscillator and regulator supply current. 5. idd can be estimated for frequencies < 14 mhz by simply multiplying the frequency of interest by the frequency sensitivity number for that range, then adding an offset of 84 a. when using these numbers to estimate i dd for > 14 mhz, the estimate should be the current at 25 mhz minus the difference in current indicated by the frequency sensitivity number. for example: v dd = 3.0 v; f = 20 mhz, i dd = 3.6 ma ? (25 mhz ? 20 mhz) x 0.088 ma/mhz = 3.16 ma assuming the same oscillator setting. 6. idle idd can be estimated by taking the current at 25 mhz minus the difference in current indicated by the frequency sensitivity number. for example: v dd = 3.0 v; f = 5 mhz, idle i dd = 1.75 ma ? (25 mhz ? 5 mhz) x 0.067 ma/mhz = 0.41 ma. table 4.2. global electrical characteristics (continued) ?40 to +85 c, 25 mhz system clock unle ss otherwise specified. see "an358: op timizing low power operation of the ?f9xx" for details on how to achieve the supply current specifications listed in this table. parameter conditions min typ max units www.datasheet.in
c8051f99x-c8051f98x 50 rev. 1.0 figure 4.1. active mode current (external cmos clock) 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 3200 3300 3400 3500 3600 3700 3800 3900 4000 4100 4200 012345678910111213141516171819202122232425 supply current (ua) frequency (mhz) f < 14 mhz oneshot enabled f > 14 mhz oneshot bypassed < 150ua/mhz 152 ua/mhz 184 ua/mhz 250 ua/mhz 180 ua/mhz 168 ua/mhz www.datasheet.in
rev. 1.0 51 c8051f99x-c8051f98x figure 4.2. idle mode current (external cmos clock) 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 3200 3300 3400 3500 3600 3700 3800 3900 4000 4100 4200 012345678910111213141516171819202122232425 supply current (ua) frequency (mhz) www.datasheet.in
c8051f99x-c8051f98x 52 rev. 1.0 table 4.3. port i/o dc electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameters conditions min typ max units output high voltage high drive strength, pndrv.n = 1 ioh = ?3 ma, port i/o push-pull ioh = ?10 a, port i/o push-pull ioh = ?10 ma, port i/o push-pull low drive strength, pndrv.n = 0 ioh = ?1 ma, port i/o push-pull ioh = ?10 a, port i/o push-pull ioh = ?3 ma, port i/o push-pull v dd ? 0.7 v dd ? 0.1 v dd ? 0.7 v dd ? 0.1 ? ? ? see chart ? ? see chart ? ? ? ? ? v output low voltage high drive strength, pndrv.n = 1 i ol = 8.5 ma i ol = 10 a i ol = 25 ma low drive strength, pndrv.n = 0 i ol = 1.4 ma i ol = 10 a i ol = 4 ma ? ? ? ? ? ? ? ? see chart ? ? see chart 0.6 0.1 ? 0.6 0.1 ? v input high voltage v dd = 2.0 to 3.6 v v dd ? 0.6 ?? v v dd = 0.9 to 2.0 v 0.7 x vdd ? ? v input low voltage v dd = 2.0 to 3.6 v ? ? 0.6 v v dd = 0.9 to 2.0 v ? ? 0.3 x vdd v input leakage ? current weak pullup off weak pullup on, v in = 0 v, v dd = 1.8 v weak pullup on, vin = 0 v, v dd = 3.6 v ? ? ? ? 4 20 1 ? 35 a www.datasheet.in
rev. 1.0 53 c8051f99x-c8051f98x figure 4.3. typical voh curves, 1.8?3.6 v typical voh (high drive mode) 0.9 1.2 1.5 1.8 2.1 2.4 2.7 3 3.3 3.6 0 5 10 15 20 25 30 35 40 45 50 load current (ma) voltage vdd = 3.6v vdd = 3.0v vdd = 2.4v vdd = 1.8v typical voh (low drive mode) 0.9 1.2 1.5 1.8 2.1 2.4 2.7 3 3.3 3.6 0123456789101112131415 load current (ma) voltage vdd = 3.6v vdd = 3.0v vdd = 2.4v vdd = 1.8v www.datasheet.in
c8051f99x-c8051f98x 54 rev. 1.0 figure 4.4. typical vol curves, 1.8?3.6 v typical vol (high drive mode) 0 0.3 0.6 0.9 1.2 1.5 1.8 -80 -70 -60 -50 -40 -30 -20 -10 0 load current (ma) voltage vdd = 3.6v vdd = 3.0v vdd = 2.4v vdd = 1.8v typical vol (low drive mode) 0 0.3 0.6 0.9 1.2 1.5 1.8 -10-9-8-7-6-5-4-3-2-1 0 load current (ma) voltage vdd = 3.6v vdd = 3.0v vdd = 2.4v vdd = 1.8v www.datasheet.in
rev. 1.0 55 c8051f99x-c8051f98x table 4.4. reset electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units rst output low voltage i ol = 1.4 ma, ??0.6 v rst input high voltage v dd = 2.0 to 3.6 v v dd ? 0.6 ?? v v dd = 0.9 to 2.0 v 0.7 x v dd ?? v rst input low voltage v dd = 2.0 to 3.6 v ??0.6 v v dd = 0.9 to 2.0 v ?? 0.3 x v dd v rst input pullup current rst = 0.0 v, vdd = 1. 8 v rst = 0.0 v, vdd = 3. 6 v ? ? 4 20 ? 30 a vdd monitor threshold (v rst ) early warning reset trigger (all power modes except sleep) 1.8 1.7 1.85 1.75 1.9 1.8 v vdd ramp time for power on vbat ramp from 0?1.8 v ?? 3 ms por monitor threshold (v por ) brownout condition (vdd falling) recovery from brownout (vdd rising) 0.45 ? 0.7 1.75 1.0 ? v missing clock detector ? timeout time from last system clock rising edge to reset initiation 100 650 1000 s minimum system clock w/ missing clock detector enabled system clock frequency which triggers a missing clock detector timeout ? 7 10 khz reset time delay delay between release of any reset source and code execution at location 0x0000 ?10? s minimum rst low time to generate a system reset 15 ? ? s v dd monitor turn-on time ? 300 ? ns v dd monitor supply ? current ?7?a www.datasheet.in
c8051f99x-c8051f98x 56 rev. 1.0 table 4.5. power management electrical specifications v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units idle mode wake-up time 2 ? 3 sysclks suspend mode wake-up time clkdiv = 0x00 ? 400 ? ns low power or precision osc. sleep mode wake-up time ? 2 ? s table 4.6. flash electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units flash size C8051F980/1/6/7, c8051f990/1/6/7 8192 ? ? bytes c8051f982/3/8/9 4096 ? ? bytes c8051f985 2048 ? ? bytes endurance 20 k 100k ? erase/write cycles erase cycle time 28 32 36 ms write cycle time 57 64 71 s table 4.7. internal precision oscillator electrical characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified; using factory-calibrated settings. parameter conditions min typ max units oscillator frequency ?40 to +85 c, v dd = 1.8?3.6 v 24 24.5 25 mhz oscillator supply current ? (from v dd ) 25 c; includes bias current of 90?100 a ?300*? a *note: does not include clock divider or clock tree supply current. table 4.8. internal low-power oscillator electrical characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified; using factory-calibrated settings. parameter conditions min typ max units oscillator frequency ?40 to +85 c, v dd = 1.8?3.6 v 18 20 22 mhz oscillator supply current ? (from v dd ) 25 c no separate bias current required ?100*? a *note: does not include clock divider or clock tree supply current. www.datasheet.in
rev. 1.0 57 c8051f99x-c8051f98x table 4.9. smartclock characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified; using factory-calibrated settings. parameter conditions min typ max units oscillator frequency (lfo) 13.1 16.4 19.7 khz table 4.10. adc0 electrical characteristics v dd = 1.8 to 3.6 v, vref = 1.65 v (refsl[1:0] = 11), ? 40 to +85 c unless otherwise specified. parameter conditions min typ max units dc accuracy resolution 12-bit mode 10-bit mode 12 10 bits integral nonlinearity 12-bit mode 1 10-bit mode ? ? 1 0.5 1.5 1 lsb differential nonlinearity (guaranteed monotonic) 12-bit mode 1 10-bit mode ? ? 0.8 0.5 1 1 lsb offset error 12-bit mode 10-bit mode ? ? <1 <1 2 2 lsb full scale error 12-bit mode 2 10-bit mode ? ? 1 1 4 2.5 lsb dynamic performance (10 khz sine-wave single-ended input, 1 db below full scale, maximum sampling rate) signal-to-noise plus distortion 3 12-bit mode 10-bit mode 62 54 65 58 ? ? db signal-to-distortion 3 12-bit mode 10-bit mode ? ? 76 73 ? ? db spurious-free dynamic range 3 12-bit mode 10-bit mode ? ? 82 75 ? ? db conversion rate sar conversion clock normal power mode low power mode ? ? ? ? 8.33 4.4 mhz conversion time in sar clocks 10-bit mode 8-bit mode 13 11 ? ? ? ? clocks track/hold acquisition time initial acquisition subsequent acquisitions (dc input, burst mode) 1.5 1.1 ? ? ? ? us throughput rate 12-bit mode 10-bit mode ? ? ? ? 75 300 ksps 1. inl and dnl specifications for 12-bit mode do not include the first or last four adc codes. 2. the maximum code in 12-bit mode is 0xfffc. the full scale error is referenced from the maximum code. 3. performance in 8-bit mode is similar to 10-bit mode. www.datasheet.in
c8051f99x-c8051f98x 58 rev. 1.0 analog inputs adc input voltage range single ended (ain+ ? gnd) 0 ? vref v absolute pin voltage with respect to gnd single ended 0 ? vdd v sampling capacitance 1x gain 0.5x gain ? 16 13 ? pf input multiplexer impedance ? 5 ? k ? power specifications power supply current ? (v dd supplied to adc0) normal power mode: conversion mode (300 ksps) tracking mode (0 ksps) low power mode: conversion mode (150 ksps) tracking mode (0 ksps) ? ? ? ? 650 740 370 400 ? ? ? ? a power supply rejection internal high speed vref external vref ? ? 67 74 ? ? db table 4.11. temperature sensor electrical characteristics v dd = 1.8 to 3.6 v, ? 40 to +85 c unless otherwise specified. parameter conditions min typ max units linearity ? 1 ? c slope ? 3.40 ? mv/c slope error* ? 40 ? v/c offset temp = 25 c ? 1025 ? mv offset error* temp = 25 c ? 18 ? mv temperature sensor turn-on time ? 1.7 ? s supply current ? 35 ? a *note: represents one standard deviation from the mean. table 4.10. adc0 electrical characteristics (continued) v dd = 1.8 to 3.6 v, vref = 1.65 v (refsl[1:0] = 11), ? 40 to +85 c unless otherwise specified. parameter conditions min typ max units 1. inl and dnl specifications for 12-bit mode do not include the first or last four adc codes. 2. the maximum code in 12-bit mode is 0xfffc. the full scale error is referenced from the maximum code. 3. performance in 8-bit mode is similar to 10-bit mode. www.datasheet.in
rev. 1.0 59 c8051f99x-c8051f98x table 4.12. voltage reference electrical characteristics v dd = 1.8 to 3.6 v, ? 40 to +85 c unless otherwise specified. parameter conditions min typ max units internal high-speed reference (refsl[1:0] = 11) output voltage ?40 to +85 c, v dd = 1.8?3.6 v 1.62 1.65 1.68 v vref turn-on time ? ? 1.5 s supply current normal power mode low power mode ? ? 260 140 ? ? a external reference (ref sl[1:0] = 00, refoe = 0) input voltage range 0 ? v dd v input current sample rate = 300 ksps; vref = 3.0 v ? 5.25 ? a www.datasheet.in
c8051f99x-c8051f98x 60 rev. 1.0 table 4.13. iref0 electrical characteristics v dd = 1.8 to 3.6 v, ? 40 to +85 c, unless otherwise specified. parameter conditions min typ max units static performance resolution 6 bits output compliance range low power mode, source high current mode, source low power mode, sink high current mode, sink 0 0 0.3 0.8 ? ? ? ? v dd ? 0.4 v dd ? 0.8 v dd v dd v integral nonlinearity ? <0.2 1.0 lsb differential nonlinearity ? <0.2 1.0 lsb offset error ? <0.1 0.5 lsb full scale error low power mode, source ? ? 5 % high current mode, source ? ? 6 % low power mode, sink ? ? 8 % high current mode, sink ? ? 8 % absolute current error low power mode sourcing 20 a ? <1 3 % dynamic performance output settling time to 1/2 lsb ? 300 ? ns startup time ? 1 ? s power consumption net power supply current ? (v dd supplied to iref0 minus any output source current) low power mode, source iref0dat = 000001 ? 10 ? a iref0dat = 111111 ? 10 ? a high current mode, source iref0dat = 000001 ? 10 ? a iref0dat = 111111 ? 10 ? a low power mode, sink iref0dat = 000001 ? 1 ? a iref0dat = 111111 ? 11 ? a high current mode, sink iref0dat = 000001 ? 12 ? a iref0dat = 111111 ? 81 ? a note: refer to ?pwm enhanced mode? on page 89 for information on how to improve iref0 resolution. www.datasheet.in
rev. 1.0 61 c8051f99x-c8051f98x table 4.14. comparator electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise noted. parameter conditions min typ max units response time: mode 0, v dd = 2.4 v, v cm * = 1.2 v cp0+ ? cp0? = 100 mv ? 120 ? ns cp0+ ? cp0? = ?100 mv ? 110 ? ns response time: mode 1, v dd = 2.4 v, v cm * = 1.2 v cp0+ ? cp0? = 100 mv ? 180 ? ns cp0+ ? cp0? = ?100 mv ? 220 ? ns response time: mode 2, v dd = 2.4 v, v cm * = 1.2 v cp0+ ? cp0? = 100 mv ? 350 ? ns cp0+ ? cp0? = ?100 mv ? 600 ? ns response time: mode 3, v dd = 2.4 v, v cm * = 1.2 v cp0+ ? cp0? = 100 mv ? 1240 ? ns cp0+ ? cp0? = ?100 mv ? 3200 ? ns common-mode rejection ratio ? 1.5 ? mv/v inverting or non- inverting input voltage range ?0.25 ? v dd + 0.25 v input capacitance ? 12 ? pf input bias current ? 1 ? na input offset voltage ?7 ? +7 mv power supply power supply rejection ? 0.1 ? mv/v power-up time vdd = 3.6 v ? 0.6 ? s vdd = 3.0 v ? 1.0 ? s vdd = 2.4 v ? 1.8 ? s vdd = 1.8 v ? 10 ? s supply current at dc mode 0 ? 23 ? a mode 1 ? 8.8 ? a mode 2 ? 2.6 ? a mode 3 ? 0.4 ? a *note: vcm is the common-mode voltage on cp0+ and cp0?. www.datasheet.in
c8051f99x-c8051f98x 62 rev. 1.0 hysteresis mode 0 hysteresis 1 (cpnhyp/n1?0 = 00) ? 0 ? mv hysteresis 2 (cpnhyp/n1?0 = 01) ? 8.5 ? mv hysteresis 3 (cpnhyp/n1?0 = 10) ? 17 ? mv hysteresis 4 (cpnhyp/n1?0 = 11) ? 34 ? mv mode 1 hysteresis 1 (cpnhyp/n1?0 = 00) ? 0 ? mv hysteresis 2 (cpnhyp/n1?0 = 01) ? 6.5 ? mv hysteresis 3 (cpnhyp/n1?0 = 10) ? 13 ? mv hysteresis 4 (cpnhyp/n1?0 = 11) ? 26 ? mv mode 2 hysteresis 1 (cpnhyp/n1?0 = 00) ? 0 1 mv hysteresis 2 (cpnhyp/n1?0 = 01) 2 5 10 mv hysteresis 3 (cpnhyp/n1?0 = 10) 5 10 20 mv hysteresis 4 (cpnhyp/n1?0 = 11) 12 20 30 mv mode 3 hysteresis 1 (cpnhyp/n1?0 = 00) ? 0 ? mv hysteresis 2 (cpnhyp/n1?0 = 01) ? 4.5 ? mv hysteresis 3 (cpnhyp/n1?0 = 10) ? 9 ? mv hysteresis 4 (cpnhyp/n1?0 = 11) ? 17 ? mv table 4.15. vreg0 electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units input voltage range 1.8 ? 3.6 v bias current normal, idle, suspend, or stop mode ? 20 ? a table 4.14. comparator electrical characteristics (continued) v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise noted. parameter conditions min typ max units *note: vcm is the common-mode voltage on cp0+ and cp0?. www.datasheet.in
rev. 1.0 63 c8051f99x-c8051f98x table 4.16. capacitive sense electrical characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified. parameter conditions min typ max units single conversion time 1 12-bit mode 13-bit mode (default) 14-bit mode 16-bit mode 20 21 23 26 25 27 29 33 40 42.5 45 50 s number of channels 24-pin packages 20-pin packages 17 16 channels capacitance per code default configuration ? 1 ? ff maximum external ? capacitive load cs0cg = 111b (default) cs0cg = 000b ? ? 45 500 ? ? pf pf maximum external ? series impedance cs0cg = 111b (default) ? 50 ? k ? power supply current cs module bias current, 25 c ? 50 60 a cs module alone, maximum code output, 25 c ? 90 125 a wake-on-cs threshold (suspend mode with regulator and cs module on) 3 ? 130 180 a notes: 1. conversion time is specified with the default configuration. 2. rms noise is equivalent to one standard deviation. peak-to-peak noise encompasses 3.3 standard deviations. the rms noise value is spec ified with the default configuration. 3. includes only current from regulator, cs module, and mcu in suspend mode. www.datasheet.in
c8051f99x-c8051f98x 64 rev. 1.0 5. sar adc with 16-bit auto -averaging accumulator and autonomous low power burst mode the adc0 on C8051F980/6 and c8051f990/6 devices is a 300 ksps, 10-bit or 75 ksps, 12-bit successive- approximation-register (sar) adc with integrated track-and-hold and programmable window detector. adc0 also has an autonomous low power burst mode which can automatically enable adc0, capture and accumulate samples, then place ad c0 in a low power shutdown mode wit hout cpu intervention. it also has a 16-bit accumulator that can automatically oversample and average the adc results. see section 5.4 for more details on using the adc in 12-bit mode. c8051f982 and c8051f988 devices only support the 10-bit mode. the adc is fully configurable under software control vi a special function registers. the adc0 operates in single-ended mode and may be configured to measure various different signals using the analog multiplexer described in ?5.7. adc0 analog multiplexer? on page 81 . the voltage reference for the adc is selected as described in ?5.9. voltage and ground reference options? on page 86 . figure 5.1. adc0 functional block diagram adc0cf amp0gn ad0tm ad08be ad0sc0 ad0sc1 ad0sc2 ad0sc3 ad0sc4 10/12-bit sar adc ref sysclk adc0h 32 adc0cn ad0cm0 ad0cm1 ad0cm2 ad0wint ad0busy ad0int bursten ad0en timer 0 overflow timer 2 overflow timer 3 overflow start conversion 000 ad0busy (w) vdd adc0lth ad0wint 001 010 011 100 cnvstr input window compare logic adc0ltl adc0gth adc0gtl adc0l ain+ from amux0 burst mode logic adc0tk adc0pwr 16-bit accumulator www.datasheet.in
rev. 1.0 65 c8051f99x-c8051f98x 5.1. output code formatting the registers adc0h and adc0l contain the high and low bytes of the output conversion code from the adc at the completion of each conv ersion. data can be right-justified or left-justified, depending on the setting of the ad0sjst[2:0]. when the repeat count is set to 1, conversion codes are represented as 10- bit unsigned integers. inputs are measured from 0 to vref x 1023/1024. example c odes are shown below for both right-justified and left-justified data. unused bits in the adc0h and adc0l registers are set to 0. when the repeat count is greater than 1, the output conversion code represents the accumulated result of the conversions performed and is updated after the last co nversion in the series is finished. sets of 4, 8, 16, 32, or 64 consecutive samples can be accumulated and represented in unsigned integer format. the repeat count can be selected using the ad0rpt bits in the adc0ac register. when a repeat count higher than 1, the adc output must be right-justified (ad0sjst = 0xx); unused bits in the adc0h and adc0l registers are set to 0. the example below shows the ri ght-justified result for various input voltages and repeat counts. notice that accumulating 2 n samples is equivalent to left-shifting by n bit positions when all samples returned from the adc have the same value. the ad0sjst bits can be used to format the contents of the 16-bit accumulator. the accumulated result can be shifted right by 1, 2, or 3 bit positions. base d on the principles of oversampling and averaging, the effective adc resolution increases by 1 bit each time the oversampling rate is increased by a factor of 4. the example below shows how to increase the effective adc resolution by 1, 2, and 3 bits to obtain an effective adc resolution of 11-bit, 12-bit, or 13-bit respectively wi thout cpu intervention. input voltage right-justified adc0h:adc0l (ad0sjst = 000) left-justified adc0h:adc0l (ad0sjst = 100) vref x 1023/1024 0x03ff 0xffc0 vref x 512/1024 0x0200 0x8000 vref x 256/1024 0x0100 0x4000 0 0x0000 0x0000 input voltage repeat count = 4 repeat count = 16 repeat count = 64 v ref x 1023/1024 0x0ffc 0x3ff0 0xffc0 v ref x 512/1024 0x0800 0x2000 0x8000 v ref x 511/1024 0x07fc 0x1ff0 0x7fc0 0 0x0000 0x0000 0x0000 input voltage repeat count = 4 shift right = 1 11-bit result repeat count = 16 shift right = 2 12-bit result repeat count = 64 shift right = 3 13-bit result v ref x 1023/1024 0x07f7 0x0ffc 0x1ff8 v ref x 512/1024 0x0400 0x0800 0x1000 v ref x 511/1024 0x03fe 0x04fc 0x0ff8 0 0x0000 0x0000 0x0000 www.datasheet.in
c8051f99x-c8051f98x 66 rev. 1.0 5.2. modes of operation adc0 has a maximum conversion speed of 300 ksps in 10-bit mode. the adc0 conversion clock (sarclk) is a divided version of the system clock when burst mode is disabled (bursten = 0), or a divided version of the low power oscillator when burst mode is enabled (bursen = 1). the clock divide value is determined by the ad0s c bits in the adc0cf register. 5.2.1. starting a conversion a conversion can be initiated in one of five ways, dep ending on the programmed states of the adc0 start of conversion mode bits (ad0cm2 ? 0) in register adc0cn. conversions may be initiated by one of the following: 1. writing a 1 to the ad0busy bit of register adc0cn 2. a timer 0 overflow (i.e., timed continuous conversions) 3. a timer 2 overflow 4. a timer 3 overflow 5. a rising edge on the cnvstr input signal (pin p0.6) writing a 1 to ad0busy provides software contro l of adc0 whereby conversions are performed "on- demand". during conversion, the ad0busy bit is set to logic 1 and reset to logic 0 when the conversion is complete. the falling edge of ad0bu sy triggers an interrupt (when enabl ed) and sets the adc0 interrupt flag (ad0int). when polling for adc conversion comple tions, the adc0 interrupt flag (ad0int) should be used. converted data is available in the adc0 data registers, adc0h:adc0l, wh en bit ad0int is logic 1. when timer 2 or timer 3 overflows are used as the conversion source, low byte overflows are used if timer 2/3 is in 8-bit mode; high byte overflows are used if timer 2/3 is in 16-bit mode. see ?25. timers? on page 276 for timer configuration. important note about using cnvstr: the cnvstr input pin also functions as port pin p0.6. when the cnvstr input is used as the adc0 conversion source, port pin p0.6 should be skipped by the digital crossbar. to configure the crossbar to skip p0.6, set to 1 bit 6 in register p0skip. see ?21. port input/output? on page 213 for details on port i/o configuration. www.datasheet.in
rev. 1.0 67 c8051f99x-c8051f98x 5.2.2. tracking modes each adc0 conversion must be preceded by a minimum tracking time in order for the converted result to be accurate. the minimum tracking time is given in table 4.10 . the ad0tm bit in register adc0cn controls the adc0 track-and-hold mode. in its defaul t state when burst mode is disabled, the adc0 input is continuously tracked, except when a conversion is in progress. when the ad0tm bit is logic 1, adc0 operates in low-power track-and-hold mode. in this mode, each conversion is preceded by a tracking period of 3 sar clocks (after the start-of-conversion signa l). when the cnvstr signal is used to initiate conversions in low-power tracking mode, adc0 tra cks only when cnvstr is low; conversion begins on the rising edge of cnvstr (see figure 5.2 ). tracking can also be disabled (shutdown) when the device is in low power standby or sleep modes. low-power track- and-hold mode is also useful when amux settings are frequently changed, due to the sett ling time requirements described in ?5.2.4. settling time requirements? on page 69 . figure 5.2. 10-bit adc track and conversion example timing (bursten = 0) write '1' to ad0busy, timer 0, timer 2, timer 1, timer 3 overflow (ad0cm[2:0]=000, 001,010 011, 101) ad0tm=1 track convert low power mode ad0tm=0 track or convert convert track low power or convert sar clocks sar clocks b. adc0 timing for internal trigger source 123456789 cnvstr (ad0cm[2:0]=100) ad0tm=1 a. adc0 timing for external trigger source sar clocks track or convert convert track ad0tm=0 track convert low power mode low power or convert 10 11 12 13 14 123456789 10 11 12 13 14 123456789 10 11 12 13 14 15 16 17 www.datasheet.in
c8051f99x-c8051f98x 68 rev. 1.0 5.2.3. burst mode burst mode is a power saving feature that allows adc0 to remain in a low power state between conversions. when burst mode is enabled, adc0 wakes from a low power state, accumulates 1, 4, 8, 16, 32, or 64 using an internal burst mode clock (approximately 20 mhz), then re-enters a low power state. since the burst mode clock is independent of the sys tem clock, adc0 can perfo rm multiple conversions then enter a low power state within a single system cl ock cycle, even if the system clock is slow (e.g. 32.768 khz), or suspended. burst mode is enabled by setting bursten to logic 1. when in burst mode, ad0en controls the adc0 idle power state (i.e. the state adc0 enters when not tr acking or performing conversions). if ad0en is set to logic 0, adc0 is powered down after each burst. if ad0en is set to logic 1, adc0 remain s enabled after each burst. on each convert start signal, adc0 is awak ened from its idle power state. if adc0 is powered down, it will automatically power up and wait th e programmable po wer-up time controlled by the ad0pwr bits. otherwise, adc0 will start tracking and converting immediately. figure 5.3 shows an example of burst mode operation with a slow system clock and a repeat count of 4. when burst mode is enabled, a single convert start will initiate a numb er of conversions e qual to th e repeat count. when burst mode is disabled, a convert start is required to initiate each conversion. in both modes, the adc0 end of conversion interrupt flag (ad0int) will be set after ?repea t count? conversions have been accumulated. similarl y, the window comparator will not compare the result to the greater-than and less-than registers until ?repeat count? conversions have been accumulated. in burst mode, tracking is determ ined by the settings in ad0pwr and ad0tk. the default settings for these registers will work in most app lications without modification; howeve r, settling time requirements may need adjustment in some applications. refer to ?5.2.4. settling time requirements? on page 69 for more details. notes: ? setting ad0tm to 1 will insert an additional 3 sar clocks of trac king before each conversion, regardless of the settings of ad0pwr and ad0tk. ? when using burst mode, care must be taken to issue a convert start signal no faster than once every four sysclk periods. this includes external convert start signals. figure 5.3. burst mode tracking example with repeat count set to 4 convert start ad0tm = 1 ad0en = 0 powered down powered down system clock t 3 c power-up and track t c t c t c power-up and track t c.. ad0tm = 0 ad0en = 0 powered down powered down c power-up and track t c t c t c power-up and track t c.. ad0pwr t = tracking set by ad0tk t3 = tracking set by ad0tm (3 sar clocks) c = converting ad0tk t 3 t 3 t 3 www.datasheet.in
rev. 1.0 69 c8051f99x-c8051f98x 5.2.4. settling time requirements a minimum amount of tracking time is required befo re each conversion can be performed, to allow the sampling capacitor voltage to settle. this tracking time is determined by the amux0 resistance, the adc0 sampling capacitance, any external source resistance, and the accuracy required for the conversion. note that in low-power tracking mode, three sar clocks ar e used for tracking at the start of every conversion. for many applications, t hese three sar clocks will meet the minimu m tracking time requirements, and higher values for the ex ternal source impedance will incr ease the required tracking time. figure 5.4 shows the equivalent adc0 input circuit. the required adc0 settling time for a given settling accuracy (sa) may be approximated by equation 5.1 . when measuring the temperature sensor output or v dd with respect to gnd, r total reduces to r mux . see ta b l e 4.10 for adc0 minimum settling time requirements as well as the mux impedance and sampling capacitor values. equation 5.1. adc0 settling time requirements where: sa is the settling accuracy, given as a fraction of an lsb (for example, 0.25 to settle within 1/4 lsb) t is the required settling time in seconds r total is the sum of the amux0 resistance and any external source resistance. n is the adc resolution in bits (10). figure 5.4. adc0 equivalent input circuits t 2 n sa ------ - ?? ?? r total c sample ? ln = r mux c sample rc input = r mux * c sample mux select p0.x note: the value of csample depends on the pga gain. see table 4.10 for details. www.datasheet.in
c8051f99x-c8051f98x 70 rev. 1.0 5.2.5. gain setting the adc has gain settings of 1x and 0.5x. in 1x mo de, the full scale reading of the adc is determined directly by v ref . in 0.5x mode, the full-scale reading of the adc occurs when the input voltage is v ref x 2. the 0.5x gain setting can be useful to obtain a higher input voltage range when using a small v ref voltage, or to measure input voltages that are between v ref and v dd . gain settings for the adc are controlled by the amp0gn bit in register adc0cf. 5.3. 8-bit mode setting the adc08be bit in register adc0cf to 1 will put the adc in 8-bit mode .in 8-bit mode, only the 8 msbs of data are converted, allowing the conversi on to be completed in two fewer sar clock cycles than a 10-bit conversion. this can result in an overall lower power consumption since the system can spend more time in a low power mode. the two lsbs of a conversion are always 00 in this mode, and the adc0l register will always read back 0x00. 5.4. 12-bit mode (C8051F980/6 and c8051f990/6 devices only) C8051F980/6 and c8051f990/6 devices have an enhanced sar converter that provides 12-bit resolution while retaining the 10- and 8-bit operating modes of the other devices in the family. when configured for 12-bit conversions, the adc performs four 10-bit co nversions using four different reference voltages and combines the results into a single 12-bit value. unlike simple averaging techniques, this method provides true 12-bit resolution of ac or dc input signals without depending on noise to provide dithering. the converter also employs a hardware dynamic element matching algorithm that reconfigures the largest elements of the internal dac for each of the four 10 -bit conversions to cancel the any matching errors, enabling the converter to achieve 12-bit linearity pe rformance to go along with its 12-bit resolution. for best performance, the low power os cillator should be selected as the system clock source while taking 12-bit adc measurements. the 12-bit mode is enabled by setting the ad012be bit (adc0ac.7) to logic 1 and configuring burst mode for four conversions as described in section 5.2.3 . the conversion can be initiated using any of the methods described in section 5.2.1 , and the 12-bit result will appear in the adc0h and adc0l registers. since the 12-bit result is formed from a combination of four 10-bit results, the maximum output value is 4 x (1023) = 4092, rather than the max value of (2^12 ? 1) = 4095 that is produced by a traditional 12-bit converter. to further increase resolution, the burst mode repeat value may be configured to any multiple of four conversions. for example, if a repeat value of 16 is selected, the adc0 output will be a 14-bit number (sum of four 12-bit numbers) with 13 effective bits of resolution. 5.5. low power mode the sar converter provides a low power mode that a llows a significant reduct ion in operating current when operating at low sar clock frequencies. low power mode is enabled by setting the ad0lpm bit (adc0pwr.7) to 1. in general, low power mode is recommended when operating with sar conversion clock frequency at 4 mhz or less. see the electrical characteristics chapter for details on power consumption and the maximum clock frequencies allowed in each mode. setting the low power mode bit reduces the bias currents in both the sar converter and in the high-speed voltage reference. www.datasheet.in
rev. 1.0 71 c8051f99x-c8051f98x table 5.1. representative conversion tim es and energy consumption for the sar adc with 1.65 v high-speed vref normal power mode low power mode 8 bit 10 bit 12 bit 8 bit 10 bit 12 bit highest nominal sar clock frequency 8.17 mhz (24.5/3) 8.17 mhz (24.5/3) 6.67 mhz (20.0/3) 4.08 mhz (24.5/6) 4.08 mhz (24.5/6) 4.00 mhz (20.0/5) total number of conversion clocks required 11 13 52 (13 x 4) 11 13 52 (13*4) total tracking time (min) 1.5 s 1.5 s 4.8 s (1.5+3 x 1.1) 1.5 s 1.5 s 4.8 s (1.5+3 x 1.1) total time for one conversion 2.85 s 3.09 s 12.6 s 4.19 s 4.68 s 17.8 s adc throughput 351 ksps 323 ksps 79 ksps 238 ksps 214 ksps 56 ksps energy per conversion 8.2 nj 8.9 nj 36.5 nj 6.5 nj 7.3 nj 27.7 nj note: this table assumes that the 24.5 mhz precision oscillator is used for 8- and 10-bit modes, and the 20 mhz low power oscillator is used for 12-bit mode. the values in the table assume that the oscillators run at their nominal frequencies. the maximum sar clock values given in ta b l e 4.10 allow for maximum oscillation frequencies of 25.0 mhz and 22 mhz for the precision and low-power oscillators, respectively, when using the given sar clock divider values. energy calculatio ns are for the adc subsystem only and do not include cpu current. 12-bit mode is only available on C8051F980/6 and c8051f990/6 devices. www.datasheet.in
c8051f99x-c8051f98x 72 rev. 1.0 sfr page = 0x0; sfr address = 0xe8; bit-addressable ; sfr definition 5.1. adc0cn: adc0 control bit 7 6 5 4 3 2 1 0 name ad0en bursten ad0int ad0busy ad0wint adc0cm[2:0] type r/w r/w r/w w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 ad0en adc0 enable. 0: adc0 disabled (low-power shutdown). 1: adc0 enabled (active and ready for data conversions). 6 bursten adc0 burst mode enable. 0: adc0 burst mode disabled. 1: adc0 burst mode enabled. 5 ad0int adc0 conversion complete interrupt flag. set by hardware upon completion of a data conversion (bursten=0), or a burst of conversions (bursten=1). can trigger an interrupt. must be cleared by soft - ware. 4 ad0busy adc0 busy. writing 1 to this bit initiates an adc conversion when adc0cm[2:0] = 000. 3 ad0wint adc0 window compare interrupt flag. set by hardware when the contents of adc0h:adc0l fall within the window speci - fied by adc0gth:adc0gtl and adc0lth:adc0ltl. can trigger an interrupt. must be cleared by software. 2:0 adc0cm[2:0] adc0 start of conversion mode select. specifies the adc0 start of conversion source. 000: adc0 conversion initiat ed on write of 1 to ad0busy. 001: adc0 conversion initiated on overflow of timer 0. 010: adc0 conversion initiated on overflow of timer 2. 011: adc0 conversion initiated on overflow of timer 3. 1xx: adc0 conversion initiated on rising edge of cnvstr. www.datasheet.in
rev. 1.0 73 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x97 sfr definition 5.2. adc0cf: adc0 configuration bit 7 6 5 4 3 2 1 0 name ad0sc[4:0] ad08be ad0tm amp0gn type r/w r/w r/w r/w reset 1 1 1 1 1 0 0 0 bit name function 7:3 ad0sc[4:0] adc0 sar conversion clock divider. sar conversion clock is derived from fclk by the following equation, where ad0sc refers to the 5-bit value held in bits ad0sc[4:0]. sar conversion clock requirements are given in ta b l e 4.10 . bursten = 0: fclk is the current system clock. bursten = 1: fclk is the 20 mhz low power oscillator, independent of the system clock. 2 ad08be adc0 8-bit mode enable. 0: adc0 operates in 10-bit mode (normal operation). 1: adc0 operates in 8-bit mode. 1 ad0tm adc0 track mode. selects between normal or delayed tracking modes. 0: normal track mode: when adc0 is enabled, conversion begins immediately fol - lowing the start-of-conversion signal. 1: delayed track mode: when adc0 is enabled, conversion begins 3 sar clock cycles following the start-of-conversion signal. the adc is allowed to track during this time. 0 amp0gn adc0 gain control. 0: the on-chip pga gain is 0.5. 1: the on-chip pga gain is 1. * *round the result up. or ad0sc fclk clk sar -------------------- 1 ? = clk sar fclk ad 0 sc 1 + ------------------ ---------- = www.datasheet.in
c8051f99x-c8051f98x 74 rev. 1.0 sfr page = 0x0; sfr address = 0xba sfr definition 5.3. adc0ac: adc0 accumu lator configuration bit 7 6 5 4 3 2 1 0 name ad012be ad0ae ad0sjst[2:0] ad0rpt[2:0] type r/w w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 ad012be adc0 12-bit mode enable. enables 12-bit mode on C8051F980/6 and c8051f990/6 devices. 0: 12-bit mode disabled. 1: 12-bit mode enabled. 6 ad0ae adc0 accumulate enable. enables multiple conversions to be accumulated when burst mode is disabled. 0: adc0h:adc0l contain the result of the latest conversion when burst mode is disabled. 1: adc0h:adc0l contain the accumulated conversion results when burst mode is disabled. software must write 0x00 00 to adc0h:adc0l to clear the accumu - lated result. this bit is write-only. always reads 0b. 5:3 ad0sjst[2:0] adc0 accumulator shift and justify. specifies the format of data read from adc0h:adc0l. 000: right justified. no shifting applied. 001: right justified. shifted right by 1 bit. 010: right justified. shifted right by 2 bits. 011: right justified. shifted right by 3 bits. 100: left justified. no shifting applied. all remaining bit combinations are reserved. 2:0 ad0rpt[2:0] adc0 repeat count. selects the number of conversions to perform and accumulate in burst mode. this bit field must be set to 000 if burst mode is disabled. 000: perform and accumulate 1 conversion. 001: perform and accumulate 4 conversions. 010: perform and accumulate 8 conversions. 011: perform and accumulate 16 conversions. 100: perform and accumulate 32 conversions. 101: perform and accumulate 64 conversions. all remaining bit combinations are reserved. www.datasheet.in
rev. 1.0 75 c8051f99x-c8051f98x sfr page = all; sfr address = 0xbb sfr definition 5.4. adc0pwr: adc0 burst mode power-up time bit 7 6 5 4 3 2 1 0 name ad0lpm ad0pwr[3:0] type r/w r r r r/w reset 00001111 bit name function 7 ad0lpm adc0 low power mode enable. enables low power mode operation. 0: low power mode disabled. 1: low power mode enabled. 6:4 unused read = 0000b; write = don?t care. 3:0 ad0pwr[3:0] adc0 burst mode power-up time. sets the time delay required for adc0 to power up from a low power state. for bursten = 0: adc0 power state controlled by ad0en. for bursten = 1 and ad0en = 1: adc0 remains enabled and does not enter a low power state after all conversions are complete. ? conversions can begin immediately following the start-of-conversion signal. for bursten = 1 and ad0en = 0: adc0 enters a low power state after all conversions are complete. ? conversions can begin a programmed delay after the start-of-conversion signal. the adc0 burst mode power-up time is programmed according to the following equation: note: setting ad0pwr to 0x04 provides a typical tracking time of 2 us for the first sample taken after the start of conversion. or ad0pwr tstartup 400 ns ---------------------- 1 ? = tstartup ad0pwr 1 + ?? 400 ns = www.datasheet.in
c8051f99x-c8051f98x 76 rev. 1.0 sfr page = all; sfr address = 0xbc sfr definition 5.5. adc0tk: adc0 burst mode track time bit 7 6 5 4 3 2 1 0 name reserved ad0tk[5:0] type r r r/w reset 0 0011110 bit name function 7 reserved read = 0b; write = must write 0b. 6 unused read = 0b; write = don?t care. 5:0 ad0tk[5:0] adc0 burst mode track time. sets the time delay between consecutiv e conversions performed in burst mode. the adc0 burst mode track time is programmed according to the following equa - tion: notes: 1. if ad0tm is set to 1, an additional 3 sar clock cycles of track time will be inserted prior to starting the conversion. 2. the burst mode track delay is not inserted prior to the first conversion. the required tracking time for the first conversion should be met by the burst mode power-up time. or ad0tk 63 ttrack 50 ns ---------------- -1 ? ?? ?? ? = ttrack 64 ad0tk ? ?? 50 ns = www.datasheet.in
rev. 1.0 77 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xbe sfr page = 0x0; sfr address = 0xbd; sfr definition 5.6. adc0h: adc0 data word high byte bit 7 6 5 4 3 2 1 0 name adc0[15:8] type r/w reset 00000000 bit name description read write 7:0 adc0[15:8] adc0 data word high byte. most significant byte of the 16-bit adc0 accumulator formatted according to the settings in ad0sjst[2:0]. set the most significant byte of the 16-bit adc0 accumulator to the value written. note: if accumulator shifting is enabled, the most significant bits of the value read will be zeros. this register should not be written when the sync bit is set to 1. sfr definition 5.7. adc0l: adc0 data word low byte bit 7 6 5 4 3 2 1 0 name adc0[7:0] type r/w reset 00000000 bit name description read write 7:0 adc0[7:0] adc0 data word low byte. least significant byte of the 16-bit adc0 accumulator formatted according to the settings in ad0sjst[2:0]. set the least significant byte of the 16-bit adc0 accumulator to the value written. note: if accumulator shifting is ena bled, the most signific ant bits of the value read will be the least signif icant bits of the accumulator high byte. this register should not be written when the sync bit is set to 1. www.datasheet.in
c8051f99x-c8051f98x 78 rev. 1.0 5.6. programmable window detector the adc programmable window detector continuously compares the adc0 output registers to user- programmed limits, and notifies the system when a desired condition is detected. this is especially effective in an interrupt-driven system, saving c ode space and cpu bandwidth while delivering faster system response times. t he window detector interrupt flag (ad0wint in register adc0cn) can also be used in polled mode. the adc0 greater-than (adc0gth, adc0gtl) and less-than (adc0lth, adc0ltl) registers hold the comparison values. the window detector flag can be programmed to indicate when measured data is inside or outside of the user-p rogrammed limits, depending on the contents of the adc0 less-than and adc0 greater-than registers. sfr page = 0x0; sfr address = 0xc4 sfr page = 0x0; sfr address = 0xc3 sfr definition 5.8. adc0gth: adc0 greater-than high byte bit 7 6 5 4 3 2 1 0 name ad0gt[15:8] type r/w reset 1 1 1 1 1 1 1 1 bit name function 7:0 ad0gt[15:8] adc0 greater-than high byte. most significant byte of the 16-bit greater-than window compare register. sfr definition 5.9. adc0gtl: adc0 great er-than low byte bit 7 6 5 4 3 2 1 0 name ad0gt[7:0] type r/w reset 1 1 1 1 1 1 1 1 bit name function 7:0 ad0gt[7:0] adc0 greater-than low byte. least significant byte of the 16-bit greater-than window compare register. note: in 8-bit mode, this register should be set to 0x00. www.datasheet.in
rev. 1.0 79 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xc6 sfr page = 0x0; sfr address = 0xc5 sfr definition 5.10. adc0lth: adc0 l ess-than high byte bit 7 6 5 4 3 2 1 0 name ad0lt[15:8] type r/w reset 00000000 bit name function 7:0 ad0lt[15:8] adc0 less-than high byte. most significant byte of the 16-bit less-than window compare register. sfr definition 5.11. adc0ltl: adc0 less-than low byte bit 7 6 5 4 3 2 1 0 name ad0lt[7:0] type r/w reset 00000000 bit name function 7:0 ad0lt[7:0] adc0 less-than low byte. least significant byte of the 16-bit less-than window compare register. note: in 8-bit mode, this register should be set to 0x00. www.datasheet.in
c8051f99x-c8051f98x 80 rev. 1.0 5.6.1. window detector in single-ended mode figure 5.5 shows two example window comparisons for right-justified data, with adc0lth:adc0ltl = 0x0080 (128d) and adc0gth:adc0gtl = 0x0040 (64d). the input voltage can range from 0 to vref x (1023/1024) with respect to gnd, and is represented by a 10-bit unsigned integer value. in the left example, an ad0wint interrup t will be generated if the adc0 conversion word (adc0h:adc0l) is within the range defined by adc0gth:adc0gtl and adc0lth:adc0ltl (if 0x0040 < adc0h:adc0l < 0x0080). in the ri ght example, and ad 0wint interrupt will be generated if the adc0 conversion word is outside of the range defined by the adc0gt and adc0lt registers (if adc0h:adc0l < 0x0040 or adc0h:adc0l > 0x0080). figure 5.6 shows an example using left- justified data with the sa me comparison values. figure 5.5. adc window compare example: right-justified single-ended data figure 5.6. adc window compare exampl e: left-justified single-ended data 5.6.2. adc0 specifications see ?4. electrical characteristics? on page 46 for a detailed listing of adc0 specifications. 0x03ff 0x0081 0x0080 0x007f 0x0041 0x0040 0x003f 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl 0x03ff 0x0081 0x0080 0x007f 0x0041 0x0040 0x003f 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint not affected ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0gth:adc0gtl adc0lth:adc0ltl 0xffc0 0x2040 0x2000 0x1fc0 0x1040 0x1000 0x0fc0 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl 0xffc0 0x2040 0x2000 0x1fc0 0x1040 0x1000 0x0fc0 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint not affected ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0lth:adc0ltl adc0gth:adc0gtl www.datasheet.in
rev. 1.0 81 c8051f99x-c8051f98x 5.7. adc0 analog multiplexer adc0 on c8051f99x-c8051f98x has an analog multiplexer, referred to as amux0. amux0 selects the positive inputs to the single-ended adc0. any of the following may be selected as the positive input: port i/o pins, the on-chip temperature sensor, regulated digital s upply voltage (output of vreg0), vdd supply, or the positive input may be connected to gnd. the adc0 input channels are selected in the adc0mx register described in sfr definition 5.12 . figure 5.7. adc0 multiplexer block diagram important note about adc0 input configuration: port pins selected as adc0 inputs should be configured as analog inputs, and should be skipped by the digital crossbar. to configure a port pin for analog input, set to 0 the corresponding bit in regist er pnmdin and disable the digital driver (pnmdout = 0 and port latch = 1). to force the crossbar to skip a port pin, set to 1 the corresponding bit in register pnskip. see section ?21. port input/output? on page 213 for more port i/o configuration details. adc0 temp sensor amux adc0mx ad0mx4 ad0mx3 ad0mx2 ad0mx1 am0mx0 ain+ p0.1 digital supply vdd programmable attenuator gain = 0.5 or 1 p1.2 p0.7 p0.5 p0.4 p0.3 p0.2 p0.6 *p1.4 p1.3 *only available on 24-pin devices. www.datasheet.in
c8051f99x-c8051f98x 82 rev. 1.0 sfr page = 0x0; sfr address = 0x96 sfr definition 5.12. adc0mx: adc0 input channel select bit 7 6 5 4 3 2 1 0 name ad0mx type r r r r/w r/w r/w r/w r/w reset 00011111 bit name function 7:5 unused read = 000b; write = don?t care. 4:0 ad0mx amux0 positive input selection. selects the positive input channel for adc0. 00000: reserved. 10000: reserved. 00001: p0.1 10001: reserved. 00010: p0.2 10010: reserved. 00011: p0.3 10011: reserved. 00100: p0.4 10100: reserved. 00101: p0.5 10101: reserved. 00110: p0.6 10110: reserved. 00111: p0.7 10111: reserved. 01000: reserved. 11000: reserved. 01001: reserved. 11001: reserved. 01010: p1.2 11010: reserved. 01011: p1.3 11011: temperature sensor 01100: p1.4 (only available on 24-pin devices) 11100: v dd supply voltage 01101: reserved. 11101: digital supply voltage (vreg0 output, 1.7 v typical) 01110: reserved. 01111: reserved. 11110: v dd supply voltage 11111: ground www.datasheet.in
rev. 1.0 83 c8051f99x-c8051f98x 5.8. temperature sensor an on-chip temperature sensor is included on the c8051f99x-c8051f98x which c an be directly accessed via the adc multiplexer in single-e nded configuration. to use the adc to measure the temperature sensor, the adc mux channel should select the temperature se nsor. the temperature sens or transfer function is shown in figure 5.8 . the output voltage (v temp ) is the positive adc input wh en the adc multiplexer is set correctly. the tempe bit in register ref0cn enables /disables the temperature sensor, as described in sfr definition 5.15 . while disabled, the temperature sensor defaults to a high impedance state and any adc measurements performed on the sensor will result in meaningless da ta. refer to ta b l e 4.10 for the slope and offset parameters of the temperature sensor. figure 5.8. temperature sensor transfer function temperature voltage v temp = slope x (temp c offset ( v at 25 celsius) slope ( v / deg c) temp c = 25 + ( - 25) + offset v temp - offset ) / slope www.datasheet.in
c8051f99x-c8051f98x 84 rev. 1.0 5.8.1. calibration the uncalibrated temperature sensor output is extrem ely linear and suitable for relative temperature mea - surements (see ta b l e 4.11 for linearity specifications). for abso lute temperature measurements, offset and/or gain calibration is recommended. typically a 1-point (offset) calibration includes the following steps: 1. control/measure the ambient temperature (this temperature must be known). 2. power the device, and delay for a few seconds to allow for self-heating. 3. perform an adc conversion with the temperature sensor selected as the positive input and gnd selected as the negative input. 4. calculate the offset characteristics, and store this value in non-volatile memory for use with subsequent temperature sensor measurements. figure 5.9 shows the typical temperature sensor error assuming a 1-point calibration at 25 c. parame - ters that affect adc meas urement, in particular the voltage re ference value, will also affect temper - ature measurement. a single-point offset measurement of the temper ature sensor is performed on each device during produc - tion test. the measurement is performed at 25 c 5 c, using the adc with the internal high speed refer - ence buffer selected as the voltage reference. the direct adc result of the measurement is stored in the sfr registers toffh and toffl, shown in sfr definition 5.13 and sfr definition 5.14 . figure 5.9. temperature sensor error with 1-point calibration (v ref = 1.65 v) -40.00 -20.00 0.00 20.00 40.00 60.00 80.00 temperature (degrees c) error (degrees c) -5.00 -4.00 -3.00 -2.00 -1.00 0.00 1.00 2.00 3.00 4.00 5.00 -5.00 -4.00 -3.00 -2.00 -1.00 0.00 1.00 2.00 3.00 4.00 5.00 www.datasheet.in
rev. 1.0 85 c8051f99x-c8051f98x sfr page = 0xf; sfr address = 0x8e sfr page = 0xf; sfr address = 0x8d sfr definition 5.13. toffh: adc0 data word high byte bit 7 6 5 4 3 2 1 0 name toff[9:2] type rrrrrrrr reset varies varies varies varies varies varies varies varies bit name function 7:0 toff[9:2] temperature sensor offset high bits. most significant bits of the 10-bit temperature sensor offset measurement. sfr definition 5.14. toffl: adc0 data word low byte bit 7 6 5 4 3 2 1 0 name toff[1:0] type rr reset variesvaries000000 bit name function 7:6 toff[1:0] temperature sensor offset low bits. least significant bits of the 10-bit temperature sensor offset measurement. 5:0 unused read = 0; write = don't care. www.datasheet.in
c8051f99x-c8051f98x 86 rev. 1.0 5.9. voltage and ground reference options the voltage reference mux is configurable to use an externally connected voltage reference, the internal voltage reference, or one of two power supply voltages (see figure 5.10 ). the ground reference mux allows the ground reference for adc0 to be selected between the ground pin (gnd) or a port pin dedicated to analog ground (p0.1/agnd). the voltage and ground reference options are configured using the ref0cn sfr described on page 88 . electrical specifications are can be found in the electrical specifications chapter. important note about the v ref and agnd inputs: port pins are used as the external v ref and agnd inputs. when using an external voltage reference or th e internal precision reference, p0.0/vref should be configured as an analog input and skipped by the di gital crossbar. when using agnd as the ground reference to adc0, p0.1/agnd should be configured as an analog input and skipped by the digital crossbar. refer to section ?21. port input/output? on page 213 for complete port i/ o configuration details. the external reference voltage must be within the range 0 ? v ref ? vdd and the external ground reference must be at the same dc voltage potential as gnd. figure 5.10. voltage reference functional block diagram vref (to adc) adc input mux p0.0/vref r1 vdd external voltage reference circuit gnd temp sensor en 00 01 10 11 ref0cn refsl0 tempe refoe refsl1 refgnd recommended bypass capacitors + 4.7 ? f0.1 ? f internal 1.8v regulated digital supply vdd internal 1.65v high speed reference gnd p0.1/agnd 0 1 ground (to adc) refgnd www.datasheet.in
rev. 1.0 87 c8051f99x-c8051f98x 5.10. external voltage reference to use an external voltage refer ence, refsl[1:0] should be set to 00. bypass capacitors should be added as recommended by the manufacturer of the external voltage reference. if the manufacturer does not pro - vide recommendations, a 4.7uf in parallel with a 0.1uf capacitor is recommended. 5.11. internal voltage reference for applications requiring the maximum number of po rt i/o pins, or very short vref turn-on time, the 1.65 v high-speed reference will be the best internal refere nce option to choose. th e high speed internal reference is selected by setting refsl[1:0] to 11. when selected , the high speed intern al reference will be automatically enabled/disabled on an as-needed basis by adc0. for applications with a non-varying power supply voltag e, using the power supply as the voltage reference can provide adc0 with added dynamic range at the cost of reduced power supply noise rejection. to use the 1.8 to 3.6 v power supply voltage (v dd ) or the 1.8 v regulated digital supply voltage as the reference source, refsl[1:0] should be set to 01 or 10, respectively. 5.12. analog ground reference to prevent ground noise generated by switching digital logic from affecting sensitive analog measurements, a separate analog ground reference op tion is available. when enabled, the ground reference for adc0 during both the tracking/sampli ng and the conversion periods is taken from the p0.1/agnd pin. any external sensors sampled by adc0 should be referenced to the p0.1/agnd pin. this pin should be connected to the ground terminal of any external sensors sampled by adc0. if an external voltage reference is used, the p0.1/agnd pin should be connected to the ground of the external reference and its associated decoupling capacitor. the separa te analog ground reference option is enabled by setting refgnd to 1. note that when sampling the intern al temperature sensor, the internal chip ground is always used for the sampling operation, regardless of the setting of the refgnd bit. similarly, whenever the internal 1.65 v high-speed reference is selected, the internal chip ground is always used during the conversion period, regardless of the setting of the refgnd bit. 5.13. temperature sensor enable the tempe bit in register ref0cn enables/disables the temperature sensor. while disabled, the temperature sensor defaults to a high impedance st ate and any adc0 measurements performed on the sensor result in meaningless data. see section ?5.8. temperature sensor? on page 83 for details on temperature sensor characteri stics when it is enabled. www.datasheet.in
c8051f99x-c8051f98x 88 rev. 1.0 sfr page = 0x0; sfr address = 0xd3 5.14. voltage reference electrical specifications see ta b l e 4.12 on page 59 for detailed voltage reference electrical specifications. sfr definition 5.15. ref0cn: voltage reference control bit 7 6 5 4 3 2 1 0 name refgnd refsl tempe type r r r/w r/w r/w r/w r r reset 00011000 bit name function 7:6 unused read = 00b; write = don?t care. 5 refgnd analog ground reference. selects the adc0 ground reference. 0: the adc0 ground reference is the gnd pin. 1: the adc0 ground reference is the p0.1/agnd pin. 4:3 refsl voltage reference select. selects the adc0 voltage reference. 00: the adc0 voltage reference is the p0.0/vref pin. 01: the adc0 voltage reference is the vdd pin. 10: the adc0 voltage reference is the internal 1.8 v digital supply voltage. 11: the adc0 voltage reference is the internal 1.65 v high speed voltage reference. 2 tempe temperature sensor enable. enables/disables the internal temperature sensor. 0: temperature sensor disabled. 1: temperature sensor enabled. 1:0 unused read = 00b; write = don?t care. www.datasheet.in
rev. 1.0 89 c8051f99x-c8051f98x 6. programmable current reference (iref0) c8051f99x-c8051f98x devices include an on-chip prog rammable current reference (source or sink) with two output current settings: low power mode and high current mode. the maximum current output in low power mode is 63 a (1 a steps) and the maximum current output in high current mode is 504 a (8 a steps). the current source/sink is controlled though the iref0c n special function register. it is enabled by setting the desired output current to a non-zero value. it is di sabled by writing 0x00 to iref0cn. the port i/o pin associated with isrc0 should be configured as an analog input and skipped in the crossbar. see section ?21. port input/output? on page 213 for more details. sfr page = 0x0; sfr address = 0xd6 6.1. pwm enhanced mode the precision of the current reference can be incr eased by fine tuning th e iref0 output using a pwm signal generated by the pca. this mode allows the ir ef0dat bits to perform a course adjustment on the iref0 output. any available pca channel can perform a fine adjustment on the iref0 output. when enabled (pwmen = 1), the cex signal selected using the pwmss bit field is internally routed to iref0 to control the on time of a current source having the weig ht of 2 lsbs. with the two least significant bits of iref0dat set to 00b, applying a 100% duty cycle on the cex signal will be equiva lent to setting the two lsbs of iref0dat to 10b. pwm enhanced mode is enabled and setup using the iref0cf register. sfr definition 6.1. iref0cn: current reference control bit 7 6 5 4 3 2 1 0 name sink mode iref0dat type r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 sink iref0 current sink enable. selects if iref0 is a current source or a current sink. 0: iref0 is a current source. 1: iref0 is a current sink. 6 mdsel iref0 output mode select. selects low power or high current mode. 0: low power mode is selected (step size = 1 a). 1: high current mode is selected (step size = 8 a). 5:0 iref0dat[5:0] iref0 data word. specifies the number of steps required to achieve the desired output current. output current = direction x step size x iref0dat. iref0 is in a low power state wh en iref0dat is set to 0x00. www.datasheet.in
c8051f99x-c8051f98x 90 rev. 1.0 sfr page = all; sfr address = 0xb9 6.2. iref0 specifications see ta b l e 4.13 on page 60 for a detailed listing of iref0 specifications. sfr definition 6.2. iref0cf: current reference configuration bit 7 6 5 4 3 2 1 0 name pwmen pwmss[2:0] type r/w r/w r/w r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 pwmen pwm enhanced mode enable. enables the pwm enhanced mode. 0: pwm enhanced mode disabled. 1: pwm enhanced mode enabled. 6:3 unused read = 0000b, write = don?t care. 2:0 pwmss[2:0] pwm source select. selects the pca channel to use fo r the fine-tuning control signal. 000: cex0 selected as fine-tuning control signal. 001: cex1 selected as fine-tuning control signal. 010: cex2 selected as fine-tuning control signal. all other values: reserved. www.datasheet.in
rev. 1.0 91 c8051f99x-c8051f98x 7. comparator c8051f99x-c8051f98x devices include an on-chi p programmable voltage comparator: comparator 0 (cpt0) shown in figure 7.1 . the comparator offers programmable response time a nd hysteresis, an analog in put multiplexer, and two outputs that are optionally available at the port pins : a digital synchronous ?latched? output (cp0), or a digital asynchronous ?raw? output (cp0a). the asynch ronous cp0a signal is available even when the system clock is not active. this allows the comparator to operate and generate an output when the device is in some low power modes. 7.1. comparator inputs each comparator performs an analog comparison of the voltage levels at its positive (cp0+) and negative (cp0-) input. the analog input mult iplexers are completely under software control and configured using sfr registers. see section ?7.6. comparator0 analog multiplexer? on page 96 for details on how to select and configure comparator inputs. important note about comparator inputs: the port pins selected as comparator inputs should be configured as analog inputs and skipped by the crossbar. see the port i/o chapter for more details on how to configure port i/o pins as analog inputs. the comparator may also be used to compare the logic level of digital signals, however, port i/o pins configured as digital inputs must be driven to a valid logic state (high or low) to avoid increased power consumption. figure 7.1. comparator 0 functional block diagram vdd cpt0cn reset decision tree + - crossbar interrupt logic q q set clr d q q set clr d (synchronizer) gnd cp0 + cp0en cp0out cp0rif cp0fif cp0hyp1 cp0hyp0 cp0hyn1 cp0hyn0 cpt0md cp0rie cp0fie cp0md1 cp0md0 cp0 cp0a cp0 rising-edge cp0 falling-edge cp0 interrupt cp0 - (asynchronous) px.x p1.1 p1.0 www.datasheet.in
c8051f99x-c8051f98x 92 rev. 1.0 7.2. comparator outputs when a comparator is enabled, its output is a logic 1 if the voltage at the positive input is higher than the voltage at the negative input. when disa bled, the comparator output is a logic 0. the comparator output is synchronized with the system clock as shown in figure 7.2 . the synchronous ?latched? output (cp0) can be polled in software (cp0out bit), used as an interr upt source, or routed to a port pin (configured for digital i/o) through the crossbar. the asynchronous ?raw? comparator output (cp0a) is used by the low power mode wake-up logic and reset decision logic. see the power options chapter and the reset sources chapter for more details on how the asynchronous comparator outputs are used to make wake-up and reset decisions. the asynchronous comparator output can also be routed directly to a port pin through the crossbar, and is available for use outside the device even if the system clock is stopped. when using a comparator as an interrupt source, comparator interrupts can be generated on rising-edge and/or falling-edge co mparator output transitions. two indepe ndent interrupt flags (cp0rif and cp0fif) allow software to determine which edge caused the comparator interrupt. the comparator rising-edge and falling-edge interrupt flags are set by hardware when a corr esponding edge is detected rega rdless of the interrupt enable state. once set, these bits remain set until cleared by software. the rising-edge and falling-edge interrupts can be individually enabled using the cp0rie and cp0fie interrupt enable bits in the cpt0md register. in or der for the cp0rif and/or cp0fif interrupt flags to generate an interrupt request to the cpu, the comparator must be enabled as an interrupt source and global interrupts must be enabled. see the interrupt handler chapter for additional information. 7.3. comparator response time comparator response time may be configured in software via the cpt0md register described on ?cpt0md: comparator 0 mode selection? on page 95 . four response time settings are available: mode 0 (fastest response time), mode 1, mode 2, and mode 3 (lowest power). selecting a longer response time reduces the comparator active supply current. the comparator also has a low power shutdown state, which is entered any time the compar ator is disabled. comparator risi ng edge and fallin g edge response times are typically not equal. see ta b l e 4.14 on page 61 for complete comparator timing and supply current specifications. 7.4. comparator hysteresis the comparator f eatures software-p rogrammable hysteresis that can be used to st abilize the comparator output while a transition is occurring on the input. using the cpt0cn register, the user can program both the amount of hysteresis voltage (referred to the input voltage) and the positive and negative-going symmetry of this hysteresis around the threshold voltage (i.e., the comparator negative input). figure 7.2 shows that when positive hysteresis is enabled, the comparator output does not transition from logic 0 to logic 1 until the comparator positive input voltage has exceeded the threshold voltage by an amount equal to the programmed hysteresis. it also show s that when negative hysteresis is enabled, the comparator output does not transition from logic 1 to logic 0 until the comparator positive input voltage has fallen below the threshold voltage by an amount equal to the programmed hysteresis. the amount of positive hysteresis is determined by the settings of the cp0hyp bits in the cpt0cn register and the amount of negative hy steresis voltage is determined by t he settings of the cp0hyn bits in the same register. settings of 20, 10, 5, or 0 mv can be programmed for both positive and negative hysteresis. see section ?table 4.14. comparator electrical characteristics? on page 61 for complete comparator hysteresis specifications. www.datasheet.in
rev. 1.0 93 c8051f99x-c8051f98x figure 7.2. comparator hysteresis plot 7.5. comparator register descriptions the sfrs used to enable and configure the comparator are described in the following register descriptions. the comparator must be enabled by setting the cp0en bit to logic 1 before it can be used. from an enabled state, a comparator can be disabled and placed in a low power state by clearing the cp0en bit to logic 0. important note about comparator settings: false rising and falling edges can be detected by the comparator while powering on or if changes are made to the hysteresis or response time control bits. therefore, it is recommended that the rising-edge and falling-edge flags be explicitly cleared to logic 0 a short time after the comparator is enabled or its mode bits have been changed. the comparator power up time is specified in section ?table 4.14. comparator electrical characteristics? on page 61 . positive hysteresis voltage (programmed with cp0hyp bits) negative hysteresis voltage (programmed by cp0hyn bits) vin- vin+ inputs circuit configuration + _ cp0+ cp0- cp0 vin+ vin- out v oh positive hysteresis disabled maximum positive hysteresis negative hysteresis disabled maximum negative hysteresis output v ol www.datasheet.in
c8051f99x-c8051f98x 94 rev. 1.0 sfr page= 0x0; sfr address = 0x9b sfr definition 7.1. cpt0cn: comparator 0 control bit 7 6 5 4 3 2 1 0 name cp0en cp0out cp0rif cp0fif cp0hyp[1:0] cp0hyn[1:0] type r/w r r/w r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 cp0en comparator0 enable bit. 0: comparator0 disabled. 1: comparator0 enabled. 6 cp0out comparator0 output state flag. 0: voltage on cp0+ < cp0 ? . 1: voltage on cp0+ > cp0 ? . 5 cp0rif comparator0 rising-edge flag. must be cleared by software. 0: no comparator0 rising edge has occu rred since this flag was last cleared. 1: comparator0 rising edge has occurred. 4 cp0fif comparator0 falling-edge flag. must be cleared by software. 0: no comparator0 falling-e dge has occurred since this flag was last cleared. 1: comparator0 falling-edge has occurred. 3-2 cp0hyp[1:0] comparator0 positive hysteresis control bits. 00: positive hysteresis disabled. 01: positive hysteresis = hysteresis 1. 10: positive hysteresis = hysteresis 2. 11: positive hysteresis = hysteresis 3 (maximum). 1:0 cp0hyn[1:0] comparator0 negative hy steresis control bits. 00: negative hysteresis disabled. 01: negative hysteresis = hysteresis 1. 10: negative hysteresis = hysteresis 2. 11: negative hysteresis = hysteresis 3 (maximum). www.datasheet.in
rev. 1.0 95 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x9d sfr definition 7.2. cpt0md: comparator 0 mode selection bit 7 6 5 4 3 2 1 0 name cp0rie cp0fie cp0md[1:0] type r/w r r/w r/w r r r/w reset 1 0 0 0 0 0 1 0 bit name function 7 reserved read = 1b, must write 1b. 6 unused read = 0b, write = don?t care. 5 cp0rie comparator0 rising-edge interrupt enable. 0: comparator0 rising-edge interrupt disabled. 1: comparator0 rising-edge interrupt enabled. 4 cp0fie comparator0 falling-edge interrupt enable. 0: comparator0 falling-edge interrupt disabled. 1: comparator0 falling-edge interrupt enabled. 3:2 unused read = 00b, write = don?t care. 1:0 cp0md[1:0] comparator0 mode select these bits affect the response time and power consumption for comparator0. 00: mode 0 (fastest response time, highest power consumption) 01: mode 1 10: mode 2 11: mode 3 (slowest response time, lowest power consumption) www.datasheet.in
c8051f99x-c8051f98x 96 rev. 1.0 7.6. comparator0 analog multiplexer comparator0 c8051f99x-c8051f98x devices has an anal og input multiplexer to connect port i/o pins and internal signals the comparator inputs; cp0+/cp0 - are the positive and negative input multiplexers for comparator0. the comparator input multip lexers directly support capacitive touc h switches. when the capacitive touch sense compare input is selected on the positive or neg ative multiplexer, any port i/o pin connected to the other multiplexer can be directly connected to a capacitive touch switch with no additional external components. the capacitive touch sense compare prov ides the appropriate reference level for detecting when the capacitive touch switches have charged or discharged through the on-chip rsense resistor. the comparator outputs can be routed to timer2 or timer3 for capturing sense capacitor?s charge and discharge time. see section ?25. timers? on page 276 for details. see applicatio n note an338 for details on capacitive touch switch sensing. any of the following may be selected as comparator inputs: port i/o pins, capacitive touch sense compare, vdd supply voltage, regulated digital su pply voltage (output of vreg0) or ground. the comparator?s supply voltage divided by 2 is also ava ilable as an input; the resistors used to divide the voltage only draw current when this setting is select ed. the comparator input mu ltiplexers ar e configured using the cpt0mx register described in sfr definition 7.3 . figure 7.3. cp0 multiplexer block diagram important note about comparator input configuration: port pins selected as comparator inputs should be configured as analog inputs, and should be skipped by the digital crossbar. to configure a port pin for analog input, set to 0 the corresponding bit in regist er pnmdin and disable the digital driver (pnmdout = 0 and port latch = 1). to force the crossbar to skip a port pin, set to 1 the corresponding bit in register pnskip. see section ?21. port input/output? on page 213 for more port i/o configuration details. cp0- input mux p1.1 + - gnd vdd vdd r r vdd r r cp0out r ? x vdd (1/3 or 2/3) x vdd capacitive touch sense compare cp0+ input mux vdd cpt0mx cmx0n3 cmx0n2 cmx0n1 cmx0n0 cmx0p3 cmx0p2 cmx0p1 cmx0p0 p1.0 vdd r r vdd r r cp0out r ? x vdd (1/3 or 2/3) x vdd cp0out rsense only enabled when capacitive touch sense compare is selected on cp0+ input mux. cp0out rsense gnd capacitive touch sense compare only enabled when capacitive touch sense compare is selected on cp0- input mux. gnd digital supply voltage www.datasheet.in
rev. 1.0 97 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x9f sfr definition 7.3. cpt0mx: comparator0 input channel select bit 7 6 5 4 3 2 1 0 name cmx0n[3:0] cmx0p[3:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 01000100 bit name function 7:4 cmx0n comparator0 negative input selection. selects the negative input channel for comparator0. 0000: reserved 1000: reserved 0001: reserved 1001: reserved 0010: reserved 1010: reserved 0011: reserved 1011: reserved 0100: p1.1 1100: capacitive touch sense ? compare 0101: reserved 1101: vdd divided by 2 0110: reserved 1110: digital supply voltage 0111: reserved 1111: ground 3:0 cmx0p comparator0 positive input selection. selects the positive input channel for comparator0. 0000: reserved 1000: reserved 0001: reserved 1001: reserved 0010: reserved 1010: reserved 0011: reserved 1011: reserved 0100: p1.0 1100: capacitive touch sense ? compare 0101: reserved 1101: vdd divided by 2 0110: reserved 1110: vdd supply voltage 0111: reserved 1111: vdd supply voltage www.datasheet.in
c8051f99x-c8051f98x 98 rev. 1.0 8. capacitive sense (cs0) the capacitive sense subsystem uses a capacitance-to -digital circuit to determine the capacitance on a port pin. the module can take measurements from different port pins using the module?s analog multiplexer. the module is enabled only when the cs0en bit (cs0cn) is set to 1. otherwise the module is in a low-power shutdown state. the module can be conf igured to take measurements on one port pin or a group of port pins, using auto-scan. a selectable gai n circuit allows the designer to adjust the maximum allowable capacitance. an accumula tor is also included, which can be configured to average multiple conversions on an input channel. interrupts can be generated when cs0 completes a conversion or when the measured value crosses a threshold defined in cs0thh:l. figure 8.1. cs0 block diagram capacitance to digital converter timer 0 overflow timer 2 overflow timer 1 overflow start conversion 000 cs0busy (w) cs0cmpf 001 010 011 100 timer 3 overflow greater than compare logic 101 initiated continuously cs0thh:l cs0dh:l auto-scan logic cs0ss cs0se cs0mx 22-bit accumulator 110 111 initiated continuously when auto-scan enabled reserved cs0cn cs0cmpf cs0cmpen cs0busy cs0int cs0pme cs0en cs0cf cs0acu0 cs0acu1 cs0acu2 cs0cm0 cs0cm1 cs0cm2 amux . . . 1x-8x cs0md1 cs0cg0 cs0cg1 cs0cg2 cs0dr0 cs0dr1 cs0md2 cs0ia0 cs0ia1 cs0ia2 cs0dt0 cs0dt1 cs0dt2 cs0cr0 cs0cr1 cs0md3 cs0lp0 cs0lp1 cs0lp2 cs0rp0 cs0rp1 cs0pm cspmmd0 cspmmd1 cp0pm piopm pcapm smbpm spipm uapm pin monitor port i/o and peripherals 12, 13, 14, or 16 bits www.datasheet.in
rev. 1.0 99 c8051f99x-c8051f98x 8.1. configuring port pins as capacitive sense inputs in order for a port pin to be measured by cs0, that port pin must be configured as an analog input (see ?21. port input/output? ). configuring the input multip lexer to a port pin not config ured as an analog input will cause the capacitive sense comparator to output incorrect measurements. 8.2. initializing the capaci tive sensing peripheral the following procedure is recommended for properly initializing the cs0 peripheral: 1. enable the cs0 block (cs0en = 1) before performing any other initializations. 2. initialize the start of conversion mode select bits (cs0cm[2:0]) to the desired mode. 3. continue initializing a ll remaining cs0 registers. 8.3. capacitive sense star t-of-conversion sources a capacitive sense conversion can be initiated in one of eight ways, depending on the programmed state of the cs0 start of conversion bits (cs0cf6:4). co nversions may be initiated by one of the following: 1. writing a 1 to the cs0busy bit of register cs0cn 2. timer 0 overflow 3. timer 2 overflow 4. timer 1 overflow 5. timer 3 overflow 6. convert continuously 7. convert continuously with auto-scan enabled 8. perform a single scan of all enabled channels conversions can be configured to be initiated co ntinuously through one of two methods. cs0 can be configured to convert at a single c hannel continuously or it can be conf igured to convert continuously with auto-scan enabled. when configured to convert continuously, conver sions will begin after the cs0busy bit in cs0cf has been set. an interrupt will be gen erated if cs0 conversion complete interrupts are enabled by setting the ecscpt bit (eie2.0). single scan mode allows all channels enabled in th e cs0scan0 and cs0scan1 registers to be scanned in a single pass. an end of scan interrupt can be enabled to trigger once all selected channels have been converted. see section ?8.9. automatic scanning (method 2?cs0smen = 1)? on page 102 for more details about this mode. the cs0 module uses a method of successive appr oximation to determine the value of an external capacitance. the number of bits the cs0 module conver ts is adjustable using the cs0cr bits in register cs0md2. conversions are 13 bits long by default, bu t they can be adjusted to 12, 13, 14, or 16 bits depending on the nee ds of the application. unconverted bits will be set to 0. shorter conv ersion lengths produce faster conversion rates, and vice-versa. applications can take advantage of faster conversion rates when the unconverted bits fall below the noise floor. note: cs0 conversion complete interrupt behavior depends on the settings of the cs0 accumulator. if cs0 is configured to accumulate multiple conversions on an input channel, a cs0 conversion complete interrupt will be generated only after the last conversion completes. ? www.datasheet.in
c8051f99x-c8051f98x 100 rev. 1.0 8.4. cs0 multiple channel enable cs0 has the capability of measuring the total capacita nce of multiple channels using a single conversion. when the multiple channel feature is enabled (cs0 mcen = 1), channels selected by cs0scan0/1 are internally shorted together and the combined node is selected as the cs0 input. this mode can be used to detect a capacitance change on multiple channels usin g a single conversion and is useful for implementing ?wake-on-multiple channels?. 8.5. cs0 gain adjustment the gain of the cs0 circuit can be adjusted in integer increments from 1x to 8x (8x is the default). high gain gives the best sensitivity and resolution for small capacitors, such as those typically implemented as touch-sensitive pcb features. to measure larger capacitance values, the gain should be lowered accordingly. the bits cs0cg[2:0] in register cs0md set the gain value. 8.6. wake from suspend cs0 has the capability of waking t he device from a low power suspend mode upon detection of a ?touch? using the digital comparator. when the cs0smen is set to 1, cs0 may also wake up the device after an end of scan event when cs0cm[2:0] are set to 101b or after each conversion when cs0cm[2:0] are set to 110b or 111b. if the accumulate feature is enabled, the device wakes up after all samples have been accumulated. the cs0woi bit in the cs0md1 regist er can be used to configure desire wake from suspend behavior. 8.7. using cs0 in applicati ons that utilize sleep mode to achieve maximum power efficiency, cs0 should be enabled only when taking a conversion and dis- abled at all other times. cs0 must be disabl ed by software prior to entering sleep mode. www.datasheet.in
rev. 1.0 101 c8051f99x-c8051f98x 8.8. automatic scanning (method 1?cs0smen = 0) cs0 can be configured to automatically scan a sequenc e of contiguous cs0 input channels by configuring and enabling auto-scan. using auto-scan with the cs0 comparator interrupt enabled allows a system to detect a change in measured capacitance without requiring any additional dedicated mcu resources. auto-scan is enabled by setting the cs0 start-of-con version bits (cs0cf6:4) to 111b. after enabling auto- scan, the starting and ending channels should be set to appropriate values in cs0ss and cs0se, respectively. writing to cs0ss when auto-scan is enabled will cause t he value written to cs0ss to be copied into cs0mx. after being enab led, writing a 1 to cs0busy will st art auto-scan conversions. when auto-scan completes the number of conversions def ined in the cs0 accumulator bits (cs0cf1:0), auto- scan configures cs0mx to the next sequential port pin configured as an analog input and begins a conversion on that channel. all other pins between cs0ss and cs0se which are set as analog inputs are grounded during the conversion. this scan sequenc e continues until cs0mx reaches the ending input channel value defined in cs0se. after one or more conversions have been take n at this channel, auto- scan configures cs0mx back to the starting input ch annel. for an example system configured to use auto- scan, please see figure ?8.2 auto-scan example? on page 101 . note: auto-scan attempts one conversion on a cs0mx channel regardless of whether that channel?s port pin has been configured as an analog input. auto-scan will also complete the current rotation when the device is halted for debugging. if auto-scan is enable d when the device enters su spend mode, auto-scan will re main enabled and running. this feature allows the device to wake from susp end through cs0 greater-than comparator event on any configured capacitive sense input included in the auto-scan sequence of inputs. figure 8.2. auto-scan example sfr configuration: a d a a d d d d d a a a a a a a p2.0 . . . pxmdin bit port pin 0 cs0mx channel p2.1 1 p2.2 2 p2.3 3 p2.4 4 p2.5 5 p2.6 6 p2.7 7 p3.0 8 p3.1 9 p3.2 10 p3.3 11 p3.4 12 p3.5 13 p3.6 14 p3.7 15 cs0ss = 0x02 cs0se = 0x0d p2mdin = 0xf2 p3mdin = 0x04 cs0cf = 0x70 cs0cn = 0x80 enables cs0 enables auto-scan as start-of- conversion source sets p2.2 as auto- scan starting channel sets p3.5 as auto- scan ending channel configures p2.3, p2.2, p2.0 as analog inputs configures p3.0-p3.1 and p3.3-p3.7 as analog inputs scans on channels not configured as analog inputs result in indeterminate values that cannot trigger a cs0 greater than interrupt event www.datasheet.in
c8051f99x-c8051f98x 102 rev. 1.0 8.9. automatic scanning (method 2?cs0smen = 1) when cs0smen is enabled, cs0 uses an alternate autoscanning method that uses the contents of cs0scan0 and cs0scan1 to determin e which channels to include in th e scan. this maximizes flexibility for application development and can result in more power efficient scanning. the following procedure can be used to configure the device for automatic scanning with cs0smen = 1. 1. set the cs0smen bit to 1. 2. select the start of conversion mode (cs0cm[2:0]) if not already configured. mode 101b is the mode of choice for most systems. 3. configure the cs0scan0 and cs0scan1 registers to enable channels in the scan. 4. configure the cs0thh:cs0thl digital comparator threshold and polarity. 5. enable wake from suspend on end of scan (c s0woi = 1) if this fu nctionality is desired. 6. set cs0ss to point to the first channel in the scan. note: cs0ss uses the same bit mapping as the cs0mx register. 7. issue a start of conversion (busy = 1). 8. enable the cs0 wakeup source and place the device in suspend mode (optional). if using mode 101b, scanning will stop once a ?touch? ha s been detected using the digital comparator. the cs0mx register will contain the channel mux value of the channel that caused the interrupt. setting the busy bit when servicing the interrupt will cause the scan to continue where it left off. scanning will also stop after all channels have been sampled and no ?touches? have been detected. if the cs0woi bit is set, a wake from suspend event w ill be generated. note: when automatic scanning is enabled, the contents of the cs0mx register are only valid when the digital comparator interrupt is set and busy = 0. 8.10. cs0 comparator the cs0 comparator compares the latest capacitive sense conversion result with the value stored in cs0thh:cs0thl. if the result is less than or equal to the stored value, the cs0cmpf bit(cs0cn:0) is set to 0. if the result is greater than the stored value, cs0cmpf is set to 1. if the cs0 conversion accumulator is configured to accumula te multiple conversion s, a comparison will not be made until the last conversion has been accumulated. an interrupt will be generated if cs0 greater-than comp arator interrupts are enabled by setting the ecsdc bit (eie2.5) when the comparator sets cs0cmpf to 1. if auto-scan is running when the comparator sets the cs0cmpf bit, no further auto-scan initiated conversions will start until firmware sets cs0busy to 1. a cs0 greater-than comparator event can wake a device from suspend mode. this feature is useful in systems configured to continuously sample one or more capacitive se nse channels. the device will remain in the low-power suspend state until the captured value of one of the scanned channels causes a cs0 greater-than comparator event to occur. it is not necessary to have cs0 comparator interrupts enabled in order to wake a device from suspend with a greater-than event. for a summary of behavior with different cs0 comp arator, auto-scan, and auto accumulator settings, please see ta b l e 8.1 . www.datasheet.in
rev. 1.0 103 c8051f99x-c8051f98x 8.11. cs0 conversion accumulator cs0 can be configured to accumulate multiple conversi ons on an input channel. the number of samples to be accumulated is configured using the cs0acu2:0 bi ts (cs0cf2:0). the accumulator can accumulate 1, 4, 8, 16, 32, or 64 samples. after the defined number of samples have been accumulated, the result is divided by either 1, 4, 8, 16, 32, or 64 (depending on the cs0acu[2:0] setting) and copied to the cs0dh:cs0dl sfrs. table 8.1. operation with auto-scan and accumulate auto-scan enabled accumulator enabled cs0 conversion complete interrupt behavior cs0 greater than interrupt behavior cs0mx behavior nn cs0int interrupt serviced after 1 conversion com- pletes interrupt serviced after 1 con- version complete s if value in cs0dh:cs0dl is greater than cs0thh:cs0thl cs0mx unchanged. ny cs0int interrupt serviced after m conversions com- plete interrupt serviced after m con- versions complete if value in cs0dh:cs0dl (post accumu- late and divide) is greater than cs0thh:cs0thl cs0mx unchanged. yn cs0int interrupt serviced after 1 conversion com- pletes interrupt serviced after con- version complete s if value in cs0dh:cs0dl is greater than cs0thh:cs0thl; auto-scan stopped if greater-than comparator detects conver- sion value is greater than cs0thh:cs0thl, cs0mx is left unchanged; otherwise, cs0mx updates to the next channel (cs0mx + 1) and wraps back to cs0ss after passing cs0se. yy cs0int interrupt serviced after m conversions com- plete interrupt serviced after m con- versions complete if value in cs0dh:cs0dl (post accumu- late and divide) is greater than cs0thh:cs0thl; auto-scan stopped if greater-than comparator detects conver- sion value is greater than cs0thh:cs0thl, cs0mx is left unchanged; otherwise, cs0mx updates to the next channel (cs0mx + 1) and wraps back to cs0ss after passing cs0se. note: m = accumulator setting (1x, 4x, 8x, 16x, 32x, 64x). www.datasheet.in
c8051f99x-c8051f98x 104 rev. 1.0 8.12. cs0 pin monitor the cs0 module provides accurate conversions in all operating modes of the cpu, peripherals and i/o ports. pin monitoring circuits are provided to improv e interference immunity from high-current output pin switching. the cs0 pin monitor register (cs0pm, sfr definition 8.14 ) controls the operation of these pin monitors. conversions in the cs0 module are immune to any change on digital inputs and immune to most output switching. even high-speed serial data transmission will not affect cs0 operation as lo ng as the output load is limited. output changes that switch large loads such as leds and heavily-loaded communications lines can affect conversion accuracy. for this reason, the cs0 module includes pin monitoring circuits that will, if enabled, automatically adjust co nversion timing if necessary to elim inate any effect from high-current output pin switching. the pin monitor enable bit should be set for any outp ut signal that is expected to drive a large load. example: the smbus in a system is heavily loaded wit h multiple slaves and a long pcb route. set the smbus pin monitor enable, smbpm = 1. example: timer2 controls an led on port 1, pin 3 to provide variable dimming. set the port sfr write monitor enable, piopm = 1. example: the spi bus is used to communicate to a nearby host. the pin monitor is not needed because the output is not heavily loaded, spipm remains = 0, the default reset state. pin monitors should not be enabled unless they are required. the pin monitor works by repeating any portion of a conversion that may ha ve been corrupted by a change on an output pin. setting pin monitor enables bits will slow cs0 conversions. the frequency of cs0 retry operations can be limited by setting the cspmmd bits. in the default (reset) state, all converter retry requests will be performed. this is the recommended setting for all applications. the number of retries per conversion can be limited to either two or four retries by changing cspmmd. limiting the number of retries per conversion ensu res that even in circumstances where extremely frequent high-power output switching occurs, conversions will be completed, though there may be some loss of accuracy due to switching noise. activity of the pin monitor circuit c an be detected by reading the pin monitor event bit, cs0pme, in register cs0cn. this bit will be set if any cs0 converter retries have occurred. it remains set un til cleared by software or a device reset. www.datasheet.in
rev. 1.0 105 c8051f99x-c8051f98x 8.13. adjusting cs0 for special situations there are several configuration options in the cs0 modu le designed to modify the operation of the circuit and address special situations. in particular, any ci rcuit with more than 500 ohms of series impedance between the sensor and the device pin may require ad justments for optimal performance. typical applica- tions which may require adjustments include: ? touch panel sensors fabricated using a resistive conductor such as indium-tin-oxide (ito). ? circuits using a high-value series resistor to is olate the sensor element for high esd protection. most systems will require no fine tuning, and the default settings for cs0dt, cs0dr, cs0ia, cs0rp and cs0lp should be used. www.datasheet.in
c8051f99x-c8051f98x 106 rev. 1.0 sfr page = 0x0; sfr address = 0xb0 sfr definition 8.1. cs0cn: capacitive sense control bit 7 6 5 4 3 2 1 0 name cs0en cs0eos cs0int cs0busy cs0cmpen reserved cs0pme cs0cmpf type r/w r r/w r/w r/w r r r reset 0000 0 00 0 bit name description 7cs0en cs0 enable. 0: cs0 disabled and in low-power mode. 1: cs0 enabled and ready to convert. 6 cs0eos cs0 end of scan interrupt flag. 0: cs0 has not completed a scan since the last time cs0eos was cleared. 1: cs0 has completed a scan. this bit is not automatically cleared by hardware. 5cs0int cs0 interrupt flag. 0: cs0 has not completed a data conversion since the last time cs0int was cleared. 1: cs0 has completed a data conversion. this bit is not automatically cleared by hardware. 4 cs0busy cs0 busy. read: 0: cs0 conversion is complete or a conversion is not currently in progress. 1: cs0 conversion is in progress. write: 0: no effect. 1: initiates cs0 conversion if cs0cm[2:0] = 000b, 110b, or 111b. 3 cs0cmpen cs0 digital comparator enable bit. enables the digital comparator, which compares accumulated cs0 conversion output to the value stored in cs0thh:cs0thl. 0: cs0 digital comparator disabled. 1: cs0 digital comparator enabled. 2 reserved read = varies. 1 cs0pme cs0 pin monitor event. set if any converter re-tries have occurr ed due to a pin monitor event. this bit remains set until cleared by firmware. 0 cs0cmpf cs0 digital comparator interrupt flag. 0: cs0 result is smaller than the value set by cs0thh and cs0thl since the last time cs0cmpf was cleared. 1: cs0 result is greater than the value set by cs0thh and cs0thl since the last time cs0cmpf was cleared. www.datasheet.in
rev. 1.0 107 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xaa sfr definition 8.2. cs0cf: ca pacitive sense configuration bit7654 3 210 name cs0smen cs0cm[2:0] cs0mcen cs0acu[2:0] type r/w r/w r/w r/w r r/w r/w r/w reset 0000 0 000 bit name description 7 cs0smen cs0 channel scan masking enable. 0: the cs0scan0 and cs0scan1 register contents are ignored. 1: the cs0scan0 and cs0scan1 registers are used to determine which channels will be inclu ded in the scan. 6:4 cs0cm[2:0] cs0 start of conversion mode select. 000: conversion initiated on ev ery write of 1 to cs0busy. 001: conversion initiated on overflow of timer 0. 010: conversion initiated on overflow of timer 2. 011: conversion initiated on overflow of timer 1. 100: conversion initiated on overflow of timer 3. when cs0smen = 0 101: reserved. 110: conversion initiated continuously on the channel selected by cs0mx after writing 1 to cs0busy. 111: conversions initiated continuously on channels from cs 0ss to cs0se after writing 1 to cs0busy. when cs0smen = 1 101: single scan mode, scans the chan nels selected by cs0scan0/1 once. 110: conversion initiated continuously on the channel selected by cs0mx after writing 1 to cs0busy. 111: auto scan mode, continuously scans the channels selected by cs0scan0/1. 3 cs0mcen cs0 multiple channel enable. 0: multiple channel feature is disabled. 1: channels selected by cs0scan0/1 are internally shorted together and the combined node is selected as the cs0 input. this mode can be used to detect a capacitance change on multiple ch annels using a single conversion. 2:0 cs0acu[2:0] cs0 accumulator mode select. 000: accumulate 1 sample. 001: accumulate 4 samples. 010: accumulate 8 samples. 011: accumulate 16 samples 100: accumulate 32 samples. 101: accumulate 64 samples. 11x: reserved. www.datasheet.in
c8051f99x-c8051f98x 108 rev. 1.0 sfr page = 0x0; sfr address = 0xee sfr page = 0x0; sfr address = 0xed sfr definition 8.3. cs0dh: ca pacitive sense data high byte bit76543210 name cs0dh[7:0] type rrrrrrrr reset 00000000 bit name description 7:0 cs0dh cs0 data high byte. stores the high byte of the last comp leted 16-bit capacitive sense conversion. sfr definition 8.4. cs0dl: ca pacitive sense data low byte bit76543210 name cs0dl[7:0] type rrrrrrrr reset 00000000 bit name description 7:0 cs0dl cs0 data low byte. stores the low byte of the last comple ted 16-bit capacitive sense conversion. www.datasheet.in
rev. 1.0 109 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xdd sfr page = 0x0; sfr address = 0xde sfr definition 8.5. cs0scan0: cap acitive sense channel scan mask 0 bit76543210 name cs0scan0[7:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name description 7:0 cs0scan[7:0] capacitive sense channel scan mask for port 0. the selected channels are included in the auto scan when scan masking is enabled (cs0smen = 1). sfr definition 8.6. cs0scan1: cap acitive sense channel scan mask 1 bit76543210 name cs0scan[5:0] type r r r/w r/w r/w r/w r/w r/w reset 00000000 bit name description 7:6 unused read = 00b; write = don?t care 5:0 cs0scan[5:0] capacitive sense channel scan mask for port 0. the selected channels are included in the auto scan when scan masking is enabled (cs0smen = 1). www.datasheet.in
c8051f99x-c8051f98x 110 rev. 1.0 sfr page = 0x0; sfr address = 0xdd sfr page = 0x0; sfr address = 0xde sfr definition 8.7. cs0s s: capacitive sense auto-scan start channel bit76543210 name cs0ss[4:0] type r r r r/w r/w r/w r/w r/w reset 00000000 bit name description 7:5 unused read = 000b; write = don?t care 4:0 cs0ss[4:0] starting channel for auto-scan. sets the first cs0 channel to be selected by the mux for capacitive sense conver- sion when auto-scan is enabled and active. all channels detailed in cs0mx sfr definition 8.15 are possible choices for this register. when auto-scan is enabled, a writ e to cs0ss will also update cs0mx. sfr definition 8.8. cs 0se: capacitive sense auto-scan end channel bit76543210 name cs0se[4:0] type r r r r/w r/w r/w r/w r/w reset 00000000 bit name description 7:5 unused read = 000b; write = don?t care 4:0 cs0se[4:0] ending channel for auto-scan. sets the last cs0 channel to be selected by the mux for capacitive sense conver- sion when auto-scan is enabled and active. all channels detailed in cs0mx sfr definition 8.15 are possible choices for this register. www.datasheet.in
rev. 1.0 111 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xfe sfr page = 0x0; sfr address = 0xfd sfr definition 8.9. cs0thh: capacitive sense comparator threshold high byte bit76543210 name cs0thh[7:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name description 7:0 cs0thh[7:0] cs0 comparator threshold high byte. high byte of the 16-bit value compared to the capacitive sense conversion result. sfr definition 8.10. cs0thl : capacitive sense compar ator threshold low byte bit76543210 name cs0thl[7:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name description 7:0 cs0thl[7:0] cs0 comparator threshold low byte. low byte of the 16-bit value compared to the capacitive sense conversion result. www.datasheet.in
c8051f99x-c8051f98x 112 rev. 1.0 sfr page = 0x0; sfr address = 0xaf sfr definition 8.11. cs0md1 : capacitive sense mode 1 bit7 6543210 name reserved cs0pol cs0dr cs0woi cs0cg[2:0] type r/w r/w r/w r/w reset 0 0000111 bit name description 7 reserved must write 0. 6cs0pol cs0 digital comparator polarity select. 0: the digital comparator generates an interrupt if the conversion is greater than the threshold. 1: the digital comparator generates an inte rrupt if the conversion is less than or equal to the threshold. 5:4 cs0dr[1:0] cs0 double reset select. these bits adjust the secondary cs0 reset time. for most touch-sensitive switches, the default (fastest) value is su fficient. see the discussion in section 8.13 for more information. 00: no additional time is used for secondary reset. 01: an additional 0.75 s is used for secondary reset. 10: an additional 1.5 s is used for secondary reset. 11: an additional 2.25 s is used for secondary reset. 3cs0woi cs0 wake on interrupt configuration. 0: wake-up event generated on digital comparator interrupt only. 1: wake-up event generated on end of scan or digital comparator interrupt. 2:0 cs0cg[2:0] cs0 capacitance gain select. these bits select the gain applied to the capacitance measurement. lower gain values increase the size of the capacitance that can be measured with the cs0 module. the capacitance gain is equivalent to cs0cg[2:0] + 1. 000: gain = 1x 001: gain = 2x 010: gain = 3x 011: gain = 4x 100: gain = 5x 101: gain = 6x 110: gain = 7x 111: gain = 8x (default) www.datasheet.in
rev. 1.0 113 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xf3 sfr definition 8.12. cs0md2 : capacitive sense mode 2 bit76543210 name cs0cr[1:0] cs0dt[ 2:0] cs0ia[2:0] type r/w r/w r/w reset 01000000 bit name description 7:6 cs0cr[1:0] cs0 conversion rate. these bits control the conversion rate of the cs0 module. see the electrical spec- ifications table for specific timing. 00: conversions last 12 internal cs0 clocks and are 12 bits in length. 01: conversions last 13 internal cs0 clocks and are 13 bits in length. 10: conversions last 14 internal cs0 clocks and are 14 bits in length. 11: conversions last 16 internal cs0 clocks.and are 16 bits in length. 5:3 cs0dt[2:0] cs0 discharge time. these bits adjust the primary cs0 reset time. for most touch-sensitive switches, the default (fastest) value is sufficient. see the discussion in section 8.13 for more information. 000: discharge time is 0.75 s (recommended for most switches) 001: discharge time is 1.0 s 010: discharge time is 1.2 s 011: discharge time is 1.5 s 100: discharge time is 2 s 101: discharge time is 3 s 110: discharge time is 6 s 111: discharge time is 12 s 2:0 cs0ia[2:0] cs0 output curre nt adjustment. these bits allow the user to adjust the ou tput current used to charge up the capac- itive sensor element. for mo st touch-sensitive switches, the default (highest) cur- rent is sufficient. see the discussion in section 8.13 for more information. 000: full current 001: 1/8 current 010: 1/4 current 011: 3/8 current 100: 1/2 current 101: 5/8 current 110: 3/4 current 111: 7/8 current www.datasheet.in
c8051f99x-c8051f98x 114 rev. 1.0 sfr page = 0xf; sfr address = 0xf3 sfr definition 8.13. cs0md3 : capacitive sense mode 3 bit76543210 name cs0rp[1:0] cs0lp[2:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name description 7:5 unused read = 000b; write = don?t care 4:3 cs0rp[1:0] cs0 ramp selection. these bits are used to compensate cs0 conversions for circuits requiring slower ramp times. for most touch-sensitive swit ches, the default (fastest) value is suffi- cient. see the discussion in section 8.13 for more information. 00: ramp time is less than 1.5 s. 01: ramp time is between 1.5 s and 3 s. 10: ramp time is between 3 s and 6 s. 11: ramp time is greater than 6 s. 2:0 cs0lp[2:0] cs0 low pass filter selection. these bits set the internal corner frequency of the cs0 low-pass filter. higher val- ues of cs0lp result in a lower internal corner frequency. for most touch-sensitive s witches, the default setting of 000b should be used. if the cs0rp bits are adjusted from their default value, the cs0lp bits should nor- mally be set to 001b. setti ngs higher than 001b will result in attenuated readings from the cs0 module and should be used only under special circumstances. see the discussion in section 8.13 for more information. www.datasheet.in
rev. 1.0 115 c8051f99x-c8051f98x sfr page = 0xf; sfr address = 0xde; sfr definition 8.14. cs0pm: ca pacitive sense pin monitor bit76543210 name uapm spipm smbpm pcapm piopm cp0pm cspmmd[1:0] type r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name description 7 uapm uart pin monitor enable. enables monitoring of the uart tx pin. 6 spipm spi pin monitor enable. enables monitoring spi output pins. 5smbpm smbus pin monitor enable. enables monitoring of the smbus pins. 4 pcapm pca pin monitor enable. enables monitoring of pca output pins. 3 piopm port i/o pin monitor enable. enables monitoring of writes to the port latch registers. 2 cp0pm cp0 pin monitor enable. enables monitoring of the comparator cp0 output. 1:0 cspmmd[1:0] cs0 pin monitor mode. selects the operation to take when a monitored signal changes state. 00: always retry bit cycles on a pin state change. 01: retry up to twice on consecutive bit cycles. 10: retry up to four times on consecutive bit cycles. 11: reserved. www.datasheet.in
c8051f99x-c8051f98x 116 rev. 1.0 8.14. capacitive sense multiplexer the input multiplexer can be controlled through tw o methods. the cs0mx register can be written to through firmware, or the register can be configured automatically using the modu les auto-scan functionality (see ?8.8. automatic scanning (method 1?cs0smen = 0)? ). figure 8.3. cs0 multiplexer block diagram cs0 cs0mux cs0mx cs0uc cs0mx3 cs0mx2 cs0mx1 cs0mx0 p0.0 p1.5 www.datasheet.in
rev. 1.0 117 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xab sfr definition 8.15. cs0mx: capa citive sense mux channel select bit76543210 name reserved reserved reserv ed reserved cs0mx[3:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name description 7:5 reserved read = 0000b; write = 0000b. 4:0 cs0mx[4:0] cs0 mux channel select. selects one of the 14 input channel s for capacitive sense conversion. value channel 0000 p0.0 0001 p0.1 0010 p0.2 0011 p0.3 0100 p0.4 0101 p0.5 0110 p0.6 0111 p0.7 1000 p1.0 1001 p1.1 1010 p1.2 1011 p1.3 1100 p1.4 (24-pin packages only) 1101 p1.5 1110 reserved 1111 reserved www.datasheet.in
c8051f99x-c8051f98x 118 rev. 1.0 9. cip-51 microcontroller the mcu system controller core is the cip-51 microcon troller. the cip-51 is fully compatible with the mcs-51? instruction set; standard 803x/805x assemblers and compilers can be used to develop software. the mcu family has a superset of all the peripherals included with a standard 8051. the cip-51 also includes on-chip debug hardware (see description in section 27 ), and interfaces directly with the analog and digital subsystems providing a complete da ta acquisition or control-system solution in a single integrated circuit. the cip-51 microcontroller core implements the standard 8051 organization and peripherals as well as additional custom peripherals and func tions to extend its capability (see figure 9.1 for a block diagram). the cip-51 includes the following features: 9.1. performance the cip-51 employs a pipelined architecture that greatly increases its instruction throughput over the standard 8051 architecture. in a standard 8051, all instructions except for mul and div take 12 or 24 system clock cycles to execute, and usua lly have a maximum system clock of 12 mhz. by contrast, the cip-51 core executes 70% of its inst ructions in one or two system clock cycles, with no instructions taking more than eight system clock cycles. figure 9.1. cip-51 block diagram - fully compatible wit h mcs-51 instruction set - 25 mips peak throughput with 25 mhz clock - 0 to 25 mhz clock frequency - extended interrupt handler - reset input - power management modes - on-chip debug logic - program and data memory security data bus tmp1 tmp2 prgm. address reg. pc incrementer alu psw data bus data bus memory interface mem_address d8 pipeline buffer data pointer interrupt interface system_irqs emulation_irq mem_control control logic a16 program counter (pc) stop clock reset idle power control register data bus sfr bus interface sfr_address sfr_control sfr_write_data sfr_read_data d8 d8 b register d8 d8 accumulator d8 d8 d8 d8 d8 d8 d8 d8 mem_write_data mem_read_data d8 sram address register sram d8 stack pointer d8 www.datasheet.in
rev. 1.0 119 c8051f99x-c8051f98x with the cip-51's maximum system clock at 25 mhz, it has a peak throughput of 25 mips. the cip-51 has a total of 109 instructions. the table below shows th e total number of instructions that require each execution time. 9.2. programming a nd debugging support in-system programming of the flash program memory and communication with on-chip debug support logic is accomplished via the silicon l abs 2-wire development interface (c2). the on-chip debug support logic facilitates full speed in-circuit debugging, a llowing the setting of hardware breakpoints, starting, stopping and single stepping th rough program execution (including interrupt service routines), examination of the program's call stack, and reading/writing the contents of registers and memory. this method of on-chip debugging is complete ly non-intrusive, requiri ng no ram, stack, timers, or other on-chip resources. c2 details can be found in section ?27. c2 interface? on page 317 . the cip-51 is supported by development tools from silicon labs and third part y vendors. silicon labs provides an integrated development environment (ide ) including editor, debugger and programmer. the ide's debugger and programmer interface to the cip-51 via the c2 interface to provide fast and efficient in-system device programming and debugging. third party macro assemblers and c compilers are also available. 9.3. instruction set the instruction set of the cip-51 system controlle r is fully compatible wit h the standard mcs-51? instruction set. standard 8051 development tools can be used to develop software for the cip-51. all cip- 51 instructions are the binary and functional equiva lent of their mcs-51? counterparts, including opcodes, addressing modes and effect on psw flags. however, instruction timing is di fferent than that of the standard 8051. 9.3.1. instruction and cpu timing in many 8051 implementations, a distinction is ma de between machine cycles and clock cycles, with machine cycles varying from 2 to 12 clock cycles in length. however, the cip-51 implementation is based solely on clock cycle timing. all instructio n timings are specified in terms of clock cycles. due to the pipelined architecture of the cip-51, most instructions execute in the same number of clock cycles as there are program bytes in the instruction. conditional branch instruct ions take one less clock cycle to complete when the branch is not taken as opposed to when the branch is taken. table 9.1 is the cip-51 instruction set summary, which includes the mnemonic, number of bytes, and number of clock cycles for each instruction. clocks to execute 1 2 2/3 3 3/4 4 4/5 5 8 number of instructions 26 50 5 14 7 3 1 2 1 www.datasheet.in
c8051f99x-c8051f98x 120 rev. 1.0 table 9.1. cip-51 instruction set summary mnemonic description bytes clock cycles arithmetic operations add a, rn add register to a 1 1 add a, direct add direct byte to a 2 2 add a, @ri add indirect ram to a 1 2 add a, #data add immediate to a 2 2 addc a, rn add register to a with carry 1 1 addc a, direct add direct byte to a with carry 2 2 addc a, @ri add indirect ram to a with carry 1 2 addc a, #data add immediate to a with carry 2 2 subb a, rn subtract register from a with borrow 1 1 subb a, direct subtract direct byte from a with borrow 2 2 subb a, @ri subtract indirect ram from a with borrow 1 2 subb a, #data subtract immediate from a with borrow 2 2 inc a increment a 1 1 inc rn increment register 1 1 inc direct increment direct byte 2 2 inc @ri increment indirect ram 1 2 dec a decrement a 1 1 dec rn decrement register 1 1 dec direct decrement direct byte 2 2 dec @ri decrement indirect ram 1 2 inc dptr increment data pointer 1 1 mul ab multiply a and b 1 4 div ab divide a by b 1 8 da a decimal adjust a 1 1 logical operations anl a, rn and register to a 1 1 anl a, direct and direct byte to a 2 2 anl a, @ri and indirect ram to a 1 2 anl a, #data and immediate to a 2 2 anl direct, a and a to direct byte 2 2 anl direct, #data and immediate to direct byte 3 3 orl a, rn or register to a 1 1 orl a, direct or direct byte to a 2 2 orl a, @ri or indirect ram to a 1 2 orl a, #data or immediate to a 2 2 orl direct, a or a to direct byte 2 2 orl direct, #data or immediate to direct byte 3 3 xrl a, rn exclusive-or register to a 1 1 xrl a, direct exclusive-or direct byte to a 2 2 xrl a, @ri exclusive-or indirect ram to a 1 2 xrl a, #data exclusive-or immediate to a 2 2 xrl direct, a exclusive-or a to direct byte 2 2 xrl direct, #data exclusive-or immediate to direct byte 3 3 www.datasheet.in
rev. 1.0 121 c8051f99x-c8051f98x clr a clear a 1 1 cpl a complement a 1 1 rl a rotate a left 1 1 rlc a rotate a left through carry 1 1 rr a rotate a right 1 1 rrc a rotate a right through carry 1 1 swap a swap nibbles of a 1 1 data transfer mov a, rn move register to a 1 1 mov a, direct move direct byte to a 2 2 mov a, @ri move indirect ram to a 1 2 mov a, #data move immediate to a 2 2 mov rn, a move a to register 1 1 mov rn, direct move direct byte to register 2 2 mov rn, #data move immediate to register 2 2 mov direct, a move a to direct byte 2 2 mov direct, rn move register to direct byte 2 2 mov direct, direct move direct byte to direct byte 3 3 mov direct, @ri move indirect ram to direct byte 2 2 mov direct, #data move immediate to direct byte 3 3 mov @ri, a move a to indirect ram 1 2 mov @ri, direct move direct byte to indirect ram 2 2 mov @ri, #data move immediate to indirect ram 2 2 mov dptr, #data16 load dptr with 16-bit constant 3 3 movc a, @a+dptr move code byte relative dptr to a 1 3 movc a, @a+pc move code byte relative pc to a 1 3 movx a, @ri move external data (8-bit address) to a 1 3 movx @ri, a move a to external data (8-bit address) 1 3 movx a, @dptr move external data (16-bit address) to a 1 3 movx @dptr, a move a to external data (16-bit address) 1 3 push direct push direct byte onto stack 2 2 pop direct pop direct byte from stack 2 2 xch a, rn exchange register with a 1 1 xch a, direct exchange direct byte with a 2 2 xch a, @ri exchange indirect ram with a 1 2 xchd a, @ri exchange low nibble of indirect ram with a 1 2 boolean manipulation clr c clear carry 1 1 clr bit clear direct bit 2 2 setb c set carry 1 1 setb bit set direct bit 2 2 cpl c complement carry 1 1 cpl bit complement direct bit 2 2 anl c, bit and direct bit to carry 2 2 table 9.1. cip-51 instruction set summary (continued) mnemonic description bytes clock cycles www.datasheet.in
c8051f99x-c8051f98x 122 rev. 1.0 anl c, /bit and complement of direct bit to carry 2 2 orl c, bit or direct bit to carry 2 2 orl c, /bit or complement of direct bit to carry 2 2 mov c, bit move direct bit to carry 2 2 mov bit, c move carry to direct bit 2 2 jc rel jump if carry is set 2 2/3 jnc rel jump if carry is not set 2 2/3 jb bit, rel jump if direct bit is set 3 3/4 jnb bit, rel jump if direct bit is not set 3 3/4 jbc bit, rel jump if direct bit is set and clear bit 3 3/4 program branching acall addr11 absolute subroutine call 2 3 lcall addr16 long subroutine call 3 4 ret return from subroutine 1 5 reti return from interrupt 1 5 ajmp addr11 absolute jump 2 3 ljmp addr16 long jump 3 4 sjmp rel short jump (relative address) 2 3 jmp @a+dptr jump indirect relative to dptr 1 3 jz rel jump if a equals zero 2 2/3 jnz rel jump if a does not equal zero 2 2/3 cjne a, direct, rel compare direct byte to a and jump if not equal 3 3/4 cjne a, #data, rel compare immediate to a and jump if not equal 3 3/4 cjne rn, #data, rel compare immediate to register and jump if not equal 3 3/4 cjne @ri, #data, rel compare immediate to indirect and jump if not equal 3 4/5 djnz rn, rel decrement register and jump if not zero 2 2/3 djnz direct, rel decrement direct byte and jump if not zero 3 3/4 nop no operation 1 1 table 9.1. cip-51 instruction set summary (continued) mnemonic description bytes clock cycles www.datasheet.in
rev. 1.0 123 c8051f99x-c8051f98x notes on registers, operands and addressing modes: rn ?register r0?r7 of the currently selected register bank. @ri ?data ram location addressed indirectly through r0 or r1. rel ?8-bit, signed (twos complement) offset relative to the first byte of the following instruction. used by sjmp and all conditional jumps. direct ?8-bit internal data location?s address. this could be a direct-access data ram location ? (0x00?0x7f) or an sfr (0x80?0xff). #data ?8-bit constant #data16 ?16-bit constant bit ?direct-accessed bit in data ram or sfr addr11 ?11-bit destination address used by acall and ajmp. the destination must be within the same 2 kb page of program memory as the first byte of the following instruction. addr16 ?16-bit destination address used by lcall an d ljmp. the destination may be anywhere within the 8 kb program memory space. there is one unused opcode (0xa5) that performs the same function as nop. all mnemonics copyrighted ? intel corporation 1980. www.datasheet.in
c8051f99x-c8051f98x 124 rev. 1.0 9.4. cip-51 regist er descriptions following are descriptions of sfrs related to the operati on of the cip-51 system controller. reserved bits should not be set to logic l. future product versions may use these bits to implement new features in which case the reset value of the bit will be logic 0, selecting the feature's default state. detailed descriptions of the remaining sfrs are included in the sections of the data sheet associated with their corresponding system function. sfr page = all; sfr address = 0x82 sfr page = all; sfr address = 0x83 sfr definition 9.1. dpl: data pointer low byte bit 7 6 5 4 3 2 1 0 name dpl[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 dpl[7:0] data pointer low. the dpl register is the low byte of the 16 -bit dptr. dptr is used to access indi - rectly addressed flash memory or xram. sfr definition 9.2. dph: data pointer high byte bit 7 6 5 4 3 2 1 0 name dph[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 dph[7:0] data pointer high. the dph register is the high byte of the 16-bit dptr. dptr is used to access indi - rectly addressed flash memory or xram. www.datasheet.in
rev. 1.0 125 c8051f99x-c8051f98x sfr page = all; sfr address = 0x81 sfr page = all; sfr address = 0xe0; bit-addressable sfr page = all; sfr addre ss = 0xf0; bit-addressable sfr definition 9.3. sp: stack pointer bit 7 6 5 4 3 2 1 0 name sp[7:0] type r/w reset 0 0 0 0 0 1 1 1 bit name function 7:0 sp[7:0] stack pointer. the stack pointer holds the location of the t op of the stack. the stack pointer is incre - mented before every push operation. the sp register defaults to 0x07 after reset. sfr definition 9.4. acc: accumulator bit 7 6 5 4 3 2 1 0 name acc[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 acc[7:0] accumulator. this register is the accumulator for arithmetic operations. sfr definition 9.5. b: b register bit 7 6 5 4 3 2 1 0 name b[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 b[7:0] b register. this register serves as a second accumu lator for certain arithmetic operations. www.datasheet.in
c8051f99x-c8051f98x 126 rev. 1.0 sfr page = all; sfr address = 0xd0; bit-addressable sfr definition 9.6. psw: program status word bit 7 6 5 4 3 2 1 0 name cy ac f0 rs[1:0] ov f1 parity type r/w r/w r/w r/w r/w r/w r reset 0 0 0 0 0 0 0 0 bit name function 7 cy carry flag. this bit is set when the last arithmetic oper ation resulted in a carry (addition) or a bor - row (subtraction). it is cleared to logi c 0 by all other arithmetic operations. 6 ac auxiliary carry flag. this bit is set when the last arithmetic operat ion resulted in a carry into (addition) or a borrow from (subtraction) the high order nibble. it is cleared to logic 0 by all other arith - metic operations. 5 f0 user flag 0. this is a bit-addressable, general purp ose flag for use under software control. 4:3 rs[1:0] register bank select. these bits select which register bank is used during register accesses. 00: bank 0, addresses 0x00-0x07 01: bank 1, addresses 0x08-0x0f 10: bank 2, addresses 0x10-0x17 11: bank 3, addresses 0x18-0x1f 2 ov overflow flag. this bit is set to 1 under the following circumstances: ?? an add, addc, or subb instruction causes a sign-change overflow. ?? a mul instruction results in an overflow (result is greater than 255). ?? a div instruction causes a divide-by-zero condition. the ov bit is cleared to 0 by the add, a ddc, subb, mul, and div instructions in all other cases. 1 f1 user flag 1. this is a bit-addressable, general purp ose flag for use under software control. 0 parity parity flag. this bit is set to logic 1 if the sum of the ei ght bits in the accumulator is odd and cleared if the sum is even. www.datasheet.in
rev. 1.0 127 c8051f99x-c8051f98x 10. memory organization the memory organization of the cip-51 system controller is similar to that of a standard 8051. there are two separate memory spaces: program memory and data memory. program and data memory share the same address space but are accessed via different instruction types. the memory organization of the c8051f99x-c8051f98x device family is shown in figure 10.1 . figure 10.1. c8051f99x-c8051f98x memory map program/data memory (flash) (direct and indirect addressing) upper 128 ram (indirect addressing only) special function registers (direct addressing only) data memory (ram) general purpose registers bit addressable lower 128 ram (direct and indirect addressing) internal data address space external data address space f 0 C8051F980/1/6/7 c8051f990/1/6/7 8 kb flash (in-system programmable in 512 byte sectors) 0x0000 0x1fff c8051f982/3/8/9 xram - 256 bytes (accessable using movx instruction) 0x0000 0x00ff unpopulated address space 0x0100 0xffff 4 kb flash (in-system programmable in 512 byte sectors) 0x0000 0x0fff c8051f985 2 kb flash (in-system programmable in 512 byte sectors) 0x0000 0x07ff www.datasheet.in
c8051f99x-c8051f98x 128 rev. 1.0 10.1. program memory the cip-51 core has a 64 kb program memory space. the c805 1f99x-c8051f98x devices implement 8 kb (C8051F980/1/6/7, c8051f990/1/6/7), 4 kb (c8051f982/3/8/9), or 2 kb (c8051f985) of this program memory space as in-system, re-pro grammable flash memory, organize d in a contiguous block from addresses 0x0000 to 0x1fff (8 kb devices), 0x0fff (4 kb devices), or 0x07ff (2 kb devices). the last byte of this contiguous block of add resses serves as the security lock byte for the device. any addresses above the lock byte are reserved. figure 10.2. flash program memory map 10.1.1. movx instruction and program memory the movx instruction in an 8051 device is typica lly used to access external data memory. on the c8051f99x-c8051f98x devices, the movx instruction is normally used to read and write on-chip xram, but can be re-configured to write and erase on-chip flash memory space. movc instructions are always used to read flash memory, while movx write instructions are used to erase and write flash. this flash access feature provides a mechanism for the c8051f99x-c8051f98x to update program code and use the program memory space for non-volatile data storage. refer to section ?14. flash memory? on page 149 for further details. 10.2. data memory the c8051f99x-c8051f98x device family include 512 bytes of ram data memory. 256 bytes of this memory is mapped into the internal ram space of the 8051. the remainder of this memory is on-chip ?external? memory. the data memory map is shown in figure 10.1 for reference. 10.2.1. internal ram there are 256 bytes of internal ram mapped into the data memory space from 0x00 through 0xff. the lower 128 bytes of data memory are used for general pu rpose registers and scratch pad memory. either direct or indirect addressing may be used to access the lower 128 bytes of data memory. locations 0x00 through 0x1f are addressable as four banks of gene ral purpose registers, each bank consisting of eight byte-wide registers. the next 16 bytes, locations 0x20 through 0x2f, ma y either be addressed as bytes or as 128 bit locations accessible with the direct addressing mode. the upper 128 bytes of data memory are accessible only by i ndirect addressing. this region occupies the same address space as the special function regist ers (sfr) but is physically separate from the sfr lock byte 0x0000 flash memory organized in 512-byte pages flash memory space lock byte page lock byte flash memory space lock byte page unpopulated address space (reserved) 0x0000 0x1ffe 0x2000 0x1e00 0xffff 0x1fff 0x0fff 0x0ffe 0x0e00 0x0bff 0x1bff unpopulated address space (reserved) 0xffff 0x1000 C8051F980/1/6/7 c8051f990/1/6/7 c8051f982/3/8/9 lock byte 0x0000 flash memory space lock byte page 0x0800 0x07fe 0x0600 0x05ff unpopulated address space (reserved) 0xffff 0x07ff c8051f985 www.datasheet.in
rev. 1.0 129 c8051f99x-c8051f98x space. the addressing mode used by an instructio n when accessing locations above 0x7f determines whether the cpu accesses the upper 128 bytes of data memory space or th e sfrs. instructions that use direct addressing will access the sfr space. instructions using indirect addressing above 0x7f access the upper 128 bytes of data memory. figure 10.1 illustrates the data memory or ganization of the c8051f99x- c8051f98x. 10.2.1.1.general purpose registers the lower 32 bytes of data memory, locations 0x00 through 0x1f, may be addressed as four banks of general-purpose registers. each bank consists of eight byte-wide registers designated r0 through r7. only one of these banks may be enabled at a time. tw o bits in the program status word, rs0 (psw.3) and rs1 (psw.4), select the active register bank (see description of the psw in sfr definition 9.6 ). this allows fast context switching when entering subrouti nes and interrupt service ro utines. indirect addressing modes use registers r0 and r1 as index registers. 10.2.1.2.bit addressable locations in addition to direct access to data memory organized as bytes, the sixteen data memory locations at 0x20 through 0x2f are also accessible as 128 individually addressable bits. each bit has a bit address from 0x00 to 0x7f. bit 0 of the byte at 0x20 has bit address 0x00 while bit7 of the byte at 0x20 has bit address 0x07. bit 7 of the byte at 0x2f has bit address 0x7f. a bit access is distinguished from a full byte access by the type of instruction used (bit source or destin ation operands as opposed to a byte source or destination). the mcs-51? assembly language allows an alternate notation for bit addressing of the form xx.b where xx is the byte address and b is the bit position within the byte. for example, the instruction: mov c, 22.3h moves the boolean value at 0x13 (bit 3 of the byte at location 0x22) into the carry flag. 10.2.1.3.stack a programmer's stack can be located anywhere in the 256-byte data memory. the stack area is designated using the stack po inter (sp) sfr. the sp will point to th e last location us ed. the next value pushed on the stack is placed at sp +1 and then sp is incremented. a re set initializes the stack pointer to location 0x07. therefore, the first value pushed on the st ack is placed at location 0x08, which is also the first register (r0) of register bank 1. thus, if more than one register bank is to be used, the sp should be initialized to a location in the data memory not being used for data storage. the stack depth can extend up to 256 bytes. 10.2.2. external ram there are 256 bytes of on-chip ram mapped into the external data memory space. all of these address locations may be accessed using the external move instruction (movx) and the data pointer (dptr), or using movx indirect addressing mode (such as @r 1) in combinat ion with the emi0cn register. www.datasheet.in
c8051f99x-c8051f98x 130 rev. 1.0 11. on-chip xram the c8051f99x-c8051f98x mcus include on-chip ram mapped into the external data memory space (xram). the external memory space may be accessed using the external move instruction (movx) with the target address specified in either the data pointer (dptr), or with the target address low byte in r0 or r1. on c8051f99x-c8051f98x devices, the target address high byte is a don?t care. when using the movx instruction to access on-chip ra m, no additional initialization is required and the movx instruction execution time is as specified in the cip-51 chapter. important note : movx write operations can be configured to target flash memory, instead of xram. see section ?14. flash memory? on page 149 for more details. the movx in struction accesses xram by default. 11.1. accessing xram the xram memory space is accessed using the mo vx instruction. the movx instruction has two forms, both of which use an indirect addressing method. th e first method uses the data pointer, dptr, a 16-bit register which contains the effect ive address of the xram location to be read from or written to. the second method uses r0 or r1 in combination with th e emi0cn register to generate the effective xram address. examples of both of these methods are given below. 11.1.1. 16-bit movx example the 16-bit form of the movx instructi on accesses the memory location po inted to by the contents of the dptr register. the following series of instructions reads the value of the byte at address 0x1234 into the accumulator a: mov dptr, #0034h ; load dptr with 16-bit address to read (0x0034) movx a, @dptr ; load contents of 0x0034 into accumulator a ? the above example uses the 16-bit immediate mov instruction to set th e contents of dptr. alternately, the dptr can be accessed through the sfr registers dph, which contains the upper 8-bits of dptr, and dpl, which contains the lower 8-bits of dptr. 11.1.2. 8-bit movx example the 8-bit form of the movx instruction uses the conten ts of r0 or r1 to determine the 8-bits of the effective address to be accessed. the following series of instructions read the contents of the byte at address 0x0034 into the accumulator a. mov r0, #34h ; load low byte of address into r0 (or r1) movx a, @r0 ; load contents of 0x0034 into accumulator a www.datasheet.in
rev. 1.0 131 c8051f99x-c8051f98x 12. special function registers the direct-access data memory locations from 0x80 to 0xff constitute the sp ecial function registers (sfrs). the sfrs provide control and data excha nge with the c8051f99x-c8051f98x's resources and peripherals. the cip-51 controller core duplicates the sf rs found in a typical 8051 implementation as well as implementing additional sfrs used to confi gure and access the sub-systems unique to the c8051f99x-c8051f98x. this allows th e addition of new functionality wh ile retaining compatibility with the mcs-51? instruction set. ta b l e 12.1 and ta b l e 12.2 list the sfrs implemented in the c8051f99x- c8051f98x device family. the sfr registers are accessed anytime the direct ad dressing mode is used to access memory locations from 0x80 to 0xff. sfrs with addresses ending in 0x0 or 0x8 (e.g., p0, tcon, scon0, ie, etc.) are bit- addressable as well as byte-addressable. all othe r sfrs are byte-addressable only. unoccupied addresses in the sfr space are rese rved for future use. accessing t hese areas will have an indeterminate effect and should be avoided. refer to the corres ponding pages of the data sheet, as indicated in ta b l e 12.3 , for a detailed description of each register. table 12.1. special function register (sfr) memory map (page 0x0) f8 spi0cn pca0l pca0h pca0cpl0 pca0cph0 cs0thl cs0thh vdm0cn f0 b p0mdin p1mdin cs0md2 smb0adr smb0adm eip1 eip2 e8 adc0cn pca0cpl1 pca0cph1 pca0cpl2 pca0cph2 cs0dl cs0dh rstsrc e0 acc xbr0 xbr1 xbr2 it01cf flwr eie1 eie2 d8 pca0cn pca0md pca0cpm0 pca0cpm1 pca0cpm2 cs0ss cs0se pca0pwm d0 psw ref0cn cs0scan0 cs0scan1 p0skip p1skip iref0cn p0mat c8 tmr2cn reg0cn tmr2rll tmr2rlh tmr2l tmr2h pmu0fl p1mat c0 smb0cn smb0cf smb0dat adc0gtl adc0gth adc0ltl adc0lth p0mask b8 ip iref0cn adc0ac adc0pwr adc0tk adc0l adc0h p1mask b0 cs0cn oscxcn oscicn oscicl pmu0cf flscl flkey a8 ie clksel cs0cf cs0mx rtc0adr rtc0dat rtc0key cs0md1 a0 p2 spi0cfg spi0ckr spi0dat p0mdout p1mdout p2mdout sfrpage 98 scon0 sbuf0 crc0cnt cpt0cn crc0flip cpt0md crc0auto cpt0mx 90 p1 tmr3cn tmr3rll tmr3rlh tmr3l tmr3h adc0mx adc0cf 88 tcon tmod tl0 tl1 th0 th1 ckcon psctl 80 p0 sp dpl dph crc0cn crc0in crc0dat pcon 0(8) 1(9) 2(a) 3(b) 4(c) 5(d) 6(e) 7(f) (bit addressable) www.datasheet.in
c8051f99x-c8051f98x 132 rev. 1.0 12.1. sfr paging to accommodate more than 128 sfrs in the 0x80 to 0xff address space, sfr paging has been imple - mented. by default, all sfr accesses target sfr pa ge 0x0 to allow access to the registers listed in ta b l e 12.1 . during device initialization, some sfrs loca ted on sfr page 0xf may need to be accessed. ta b l e 12.2 lists the sfrs accessible from sfr page 0x0f. some sfrs are accessible from both pages, including the sfrpage regi ster. sfrs only accessible from page 0xf are in bold . the following procedure should be used when accessing sfrs on page 0xf: 1. save the current interr upt state (ea_save = ea). 2. disable interrupts (ea = 0). 3. set sfrpage = 0xf. 4. access the sfrs located on sfr page 0xf. 5. set sfrpage = 0x0. 6. restore interrupt state (ea = ea_save). table 12.2. special function register (sfr) memory map (page 0xf) f8 f0 b cs0md3 eip1 eip2 e8 e0 acc revid deviceid flwr eie1 eie2 d8 cs0pm d0 psw c8 c0 b8 iref0cf adc0pwr adc0tk b0 pmu0md a8 ie clksel a0 p2 sfrpage 98 p0drv crc0cnt p1drv crc0flip p2drv crc0auto 90 p1 88 toffl toffh 80 p0 sp dpl dph crc0cn crc0in crc0dat pcon 0(8) 1(9) 2(a) 3(b) 4(c) 5(d) 6(e) 7(f) (bit addressable) www.datasheet.in
rev. 1.0 133 c8051f99x-c8051f98x sfr page = all; sfr address = 0xa7 sfr definition 12.1. sfr page: sfr page bit 7 6 5 4 3 2 1 0 name sfrpage[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 sfrpage[7:0] sfr page. specifies the sfr page used when reading, writing, or modifying special function registers. table 12.3. special function registers sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page acc 0xe0 all accumulator 125 adc0ac 0xba 0x0 adc0 accumulator configuration 74 adc0cf 0x97 0x0 adc0 configuration 73 adc0cn 0xe8 0x0 adc0 control 72 adc0gth 0xc4 0x0 adc0 greater-than compare high 78 adc0gtl 0xc3 0x0 adc0 greater-than compare low 78 adc0h 0xbe 0x0 adc0 high 77 adc0l 0xbd 0x0 adc0 low 77 adc0lth 0xc6 0x0 adc0 less-than compare word high 79 adc0ltl 0xc5 0x0 adc0 less-than compare word low 79 adc0mx 0x96 0x0 amux0 channel select 82 adc0pwr 0xbb all adc0 burst mode power-up time 75 adc0tk 0xbc all adc0 tracking control 76 b 0xf0 all b register 125 ckcon 0x8e 0x0 clock control 277 clksel 0xa9 all clock select 191 cpt0cn 0x9b 0x0 comparator0 control 94 cpt0md 0x9d 0x0 comparator0 mode selection 95 cpt0mx 0x9f 0x0 comparator0 mux selection 97 crc0auto 0x9e all crc0 automatic control 175 crc0cn 0x84 all crc0 control 173 crc0cnt 0x9a all crc0 automatic flash sector count 176 crc0dat 0x86 all crc0 data 174 crc0flip 0x9c all crc0 flip 177 crc0in 0x85 all crc0 input 174 cs0cf 0xaa 0x0 cs0 configuration 107 cs0cn 0xb0 0x0 cs0 control 106 www.datasheet.in
c8051f99x-c8051f98x 134 rev. 1.0 cs0dh 0xee 0x0 cs0 data high byte 108 cs0dl 0xed 0x0 cs0 data low byte 108 cs0md1 0xaf 0x0 cs0 mode1 112 cs0md2 0xf3 0x0 cs0 mode 2 113 cs0md3 0xf3 0xf cs0 mode 3 114 cs0mx 0xab 0x0 cs0 mux channel select 117 cs0pm 0xde 0xf cs0 power management 115 cs0scan0 0xd2 0x0 cs0 scan channel enable 0 109 cs0scan1 0xd3 0x0 cs0 scan channel enable 1 109 cs0se 0xde 0x0 cs0 auto-scan end channel 110 cs0ss 0xdd 0x0 cs0 auto-scan start channel 110 cs0thh 0xfe 0x0 cs0 comparator threshold high byte 111 cs0thl 0xfd 0x0 cs0 comparator threshold low byte 111 deviceid 0xe3 0xf device id 153 dph 0x83 all data pointer high 124 dpl 0x82 all data pointer low 124 eie1 0xe6 all extended interrupt enable 1 143 eie2 0xe7 all extended interrupt enable 2 145 eip1 0xf6 all extended interrupt priority 1 144 eip2 0xf7 all extended interrupt priority 2 146 flkey 0xb7 all flash lock and key 159 flscl 0xb6 0x0 flash scale register 160 flwr 0xe5 all flash write only register 160 ie 0xa8 all interrupt enable 141 ip 0xb8 all interrupt priority 142 iref0cf 0xb9 all current reference iref0 configuration 90 iref0cn 0xd6 0x0 current reference iref0 control 89 it01cf 0xe4 0x0 int0/int1 configuration 148 oscicl 0xb3 0x0 internal oscilla tor calibration 193 oscicn 0xb2 0x0 internal oscillator control 192 oscxcn 0xb1 0x0 external oscillator control 194 p0 0x80 all port 0 latch 226 p0drv 0x99 0xf port 0 drive strength 228 p0mask 0xc7 0x0 port 0 mask 223 p0mat 0xd7 0x0 port 0 match 223 p0mdin 0xf1 0x0 port 0 input mode configuration 227 p0mdout 0xa4 0x0 port 0 output mode configuration 227 p0skip 0xd4 0x0 port 0 skip 226 p1 0x90 all port 1 latch 229 p1drv 0x9b 0xf port 1 drive strength 231 p1mask 0xbf 0x0 port 1 mask 224 p1mat 0xcf 0x0 port 1 match 224 p1mdin 0xf2 0x0 port 1 input mode configuration 230 p1mdout 0xa5 0x0 port 1 output mode configuration 226 table 12.3. special function registers (continued) sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page www.datasheet.in
rev. 1.0 135 c8051f99x-c8051f98x p1skip 0xd5 0x0 port 1 skip 229 p2 0xa0 all port 2 latch 231 p2drv 0x9d 0xf port 2 drive strength 232 p2mdout 0xa6 0x0 port 2 output mode configuration 232 pca0cn 0xd8 0x0 pca0 control 311 pca0cph0 0xfc 0x0 pca0 capture 0 high 316 pca0cph1 0xea 0x0 pca0 capture 1 high 316 pca0cph2 0xec 0x0 pca0 capture 2 high 316 pca0cpl0 0xfb 0x0 pca0 capture 0 low 316 pca0cpl1 0xe9 0x0 pca0 capture 1 low 316 pca0cpl2 0xeb 0x0 pca0 capture 2 low 316 pca0cpm0 0xda 0x0 pca0 module 0 mode register 314 pca0cpm1 0xdb 0x0 pca0 module 1 mode register 314 pca0cpm2 0xdc 0x0 pca0 module 2 mode register 314 pca0h 0xfa 0x0 pca0 counter high 315 pca0l 0xf9 0x0 pca0 counter low 315 pca0md 0xd9 0x0 pca0 mode 312 pca0pwm 0xdf 0x0 pca0 pwm configuration 313 pcon 0x87 all power control 169 pmu0cf 0xb5 0x0 pmu0 configuration 166 pmu0fl 0xce 0x0 pmu0 flag register 167 pmu0md 0xb5 0xf pmu0 mode 168 psctl 0x8f all program store r/w control 158 psw 0xd0 all program status word 126 ref0cn 0xd1 0x0 voltage reference control 88 reg0cn 0xc9 0x0 voltage regulator (reg0) control 178 revid 0xe2 0xf revision id 154 rstsrc 0xef 0x0 reset source configuration/status 185 rtc0adr 0xac 0x0 rtc0 address 200 rtc0dat 0xad 0x0 rtc0 data 200 rtc0key 0xae 0x0 rtc0 key 199 sbuf0 0x99 0x0 uart0 data buffer 261 scon0 0x98 0x0 uart0 control 260 sfrpage 0xa7 all sfr page 133 smb0adm 0xf5 0x0 smbus slave address mask 245 smb0adr 0xf4 0x0 smbus slave address 245 smb0cf 0xc1 0x0 smbus0 configuration 240 smb0cn 0xc0 0x0 smbus0 control 242 smb0dat 0xc2 0x0 smbus0 data 246 sp 0x81 all stack pointer 125 spi0cfg 0xa1 0x0 spi0 configuration 270 spi0ckr 0xa2 0x0 spi0 clock rate control 272 spi0cn 0xf8 0x0 spi0 control 271 spi0dat 0xa3 0x0 spi0 data 272 table 12.3. special function registers (continued) sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page www.datasheet.in
c8051f99x-c8051f98x 136 rev. 1.0 tcon 0x88 0x0 timer/counter control 282 th0 0x8c 0x0 timer/counter 0 high 285 th1 0x8d 0x0 timer/counter 1 high 285 tl0 0x8a 0x0 timer/counter 0 low 284 tl1 0x8b 0x0 timer/counter 1 low 284 tmod 0x89 0x0 timer/counter mode 283 tmr2cn 0xc8 0x0 timer/counter 2 control 289 tmr2h 0xcd 0x0 timer/counter 2 high 291 tmr2l 0xcc 0x0 timer/counter 2 low 291 tmr2rlh 0xcb 0x0 timer/counter 2 reload high 290 tmr2rll 0xca 0x0 timer/counter 2 reload low 290 tmr3cn 0x91 0x0 timer/counter 3 control 295 tmr3h 0x95 0x0 timer/counter 3 high 297 tmr3l 0x94 0x0 timer/counter 3 low 297 tmr3rlh 0x93 0x0 timer/counter 3 reload high 296 tmr3rll 0x92 0x0 timer/counter 3 reload low 296 toffh 0x8e 0xf temperature offset high 85 toffl 0x8d 0xf temperature offset low 85 vdm0cn 0xff 0x0 vdd monitor control 182 xbr0 0xe1 0x0 port i/o crossbar control 0 220 xbr1 0xe2 0x0 port i/o crossbar control 1 221 xbr2 0xe3 0x0 port i/o crossbar control 2 222 table 12.3. special function registers (continued) sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page www.datasheet.in
rev. 1.0 137 c8051f99x-c8051f98x 13. interrupt handler the c8051f99x-c8051f98x microcontroller family in cludes an extended interrupt system supporting multiple interrupt sources and two priority levels. the allocation of interrupt sources between on-chip peripherals and external input pins varies accordin g to the specific version of the device. refer to ta b l e 13.1, ?interrupt summary,? on page 139 for a detailed listing of all interrupt sources supported by the device. refer to the data sheet section associated with a particular on-chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s). each interrupt source has one or more associated interrupt-pending flag(s) located in an sfr or an indirect register. when a peripheral or external s ource meets a valid interrupt condition, the associated interrupt-pending flag is set to logic 1. if both global interrupts and the sp ecific interrupt source is enabled, a cpu interrupt request is generated when the interrupt-pending flag is set. as soon as execution of the cu rrent instruction is complete, the cpu generates an lcall to a predetermined address to begin execution of an interrup t service routine (isr). each isr must end with an reti instruction, which re turns program execution to the next instru ction that would have been executed if the interrupt request had not occurred. if interrupts are not enabled, the interrupt-pending flag is ignored by the hardware and program execution continues as no rmal. (the interrupt-pending flag is set to logic 1 regardless of the interrupt's enable/disable state.) some interrupt-pending flags are automatically cleared by hardware when the cpu vectors to the isr. however, most are not cleared by the hardware and must be cleared by software before returning from the isr. if an interrupt-pending flag remains set after the cpu completes the return-from-interrupt (reti) instruction, a new interr upt request will be gen erated immediately and the cpu will re-enter the isr after the completion of th e next instruction. 13.1. enabling interrupt sources each interrupt source can be individually enabled or disabled through the use of an associated interrupt enable bit in the interrupt enable and extended interrupt enable sfrs. however, interrupts must first be globally enabled by setting the ea bit (ie.7) to logic 1 before the individual interrupt enables are recognized. setting the ea bit to logic 0 disables all in terrupt sources regardless of the individual interrupt- enable settings. note that interrupts which occur wh en the ea bit is set to logic 0 will be held in a pending state, and will not be serviced until the ea bit is set back to logic 1. 13.2. mcu interrupt sources and vectors the cpu services interrupts by generating an lca ll to a predetermined address (the interrupt vector address) to begin execution of an interrupt servic e routine (isr). the interrupt vector addresses associated with each interrupt source are listed in ta b l e 13.1 on page 139 . software should ensure that the interrupt vector for each enabled interrupt source contains a valid interrupt service routine. software can simulate an interrupt by setting any interrupt-pending flag to logic 1. if interrupts are enabled for the flag, an interrupt request will be gene rated and the cpu will vector to the isr address associated with the interrupt-pending flag. www.datasheet.in
c8051f99x-c8051f98x 138 rev. 1.0 13.3. interrupt priorities each interrupt source can be individually programmed to one of two priority levels: low or high. a low priority interrupt service routine can be preempted by a high priority interrupt. a high priority interrupt cannot be preempted. if a high priority interrupt preempts a low priority interrupt, the low priority interrupt will finish execution after the high pr iority interrupt completes. each in terrupt has an asso ciated interrupt priority bit in in the interrupt priority and extended in terrupt priority registers used to configure its priority level. low priority is the default. if two interrupts are recognized simultaneously, the interrup t with the higher priority is serviced first. if both interrupts have the same priority level, a fixed priority order is used to arbitrate. see ta b l e 13.1 on page 139 to determine the fixed priority order used to arbitrate between simultaneously recognized interrupts. 13.4. interrupt latency interrupt response time depends on the state of the cpu when the interrupt occurs. pending interrupts are sampled and priority decoded each sys tem clock cycle. therefore, the fa stest possible response time is 7 system clock cycles: 1 clock cycle to detect the interrupt, 1 clock cycle to execute a single instruction, and 5 clock cycles to complete the lcall to the isr. if an interrupt is pending when a reti is executed, a single instruction is executed before an lcall is made to service the pending interrupt. therefore, the maximum response time for an interrupt (when no other interrupt is currently being serviced or the new interrupt is of greater priority) oc curs when the cpu is performing an re ti instruction followed by a div as the next instruction. in this case, the response time is 19 system clock cycles: 1 clock cycle to detect the interrupt, 5 clock cycles to execute the reti, 8 clock cycles to complete the div instruction and 5 clock cycles to execute the lcall to the isr. if the cpu is executing an isr for an interrupt with equal or higher priority, the new interrupt will not be serviced until the current isr co mpletes, includi ng the reti and following instruction. www.datasheet.in
rev. 1.0 139 c8051f99x-c8051f98x table 13.1. interrupt summary interrupt source interrupt vector priority order pending flag bit addressable? cleared by hw? enable flag priority control reset 0x0000 to p none n/a n/a always enabled always highest external interrupt 0 ( int0 ) 0x0003 0 ie0 (tcon.1) y y ex0 (ie.0) px0 (ip.0) timer 0 overflow 0x000b 1 tf0 (tcon.5) y y et0 (ie.1) pt0 (ip.1) external interrupt 1 ( int1 ) 0x0013 2 ie1 (tcon.3) y y ex1 (ie.2) px1 (ip.2) timer 1 overflow 0x001b 3 tf1 (tcon.7) y y et1 (ie.3) pt1 (ip.3) uart0 0x0023 4 ri0 (scon0.0) ti0 (scon0.1) y n es0 (ie.4) ps0 (ip.4) timer 2 overflow 0x002b 5 tf2h (tmr2cn.7) tf2l (tmr2cn.6) y n et2 (ie.5) pt2 (ip.5) spi0 0x0033 6 spif (spi0cn.7) ? wcol (spi0cn.6) modf (spi0cn.5) rxovrn (spi0cn.4) y n espi0 (ie.6) pspi0 (ip.6) smb0 0x003b 7 si (smb0cn.0) y n esmb0 (eie1.0) psmb0 (eip1.0) smartclock alarm 0x0043 8 alrm (rtc0cn.2) 2 n n eartc0 (eie1.1) partc0 (eip1.1) adc0 window comparator 0x004b 9 ad0wint (adc0cn.3) y n ewadc0 (eie1.2) pwadc0 (eip1.2) adc0 end of conversion 0x0053 10 ad0int (adc0cn.5) y n eadc0 (eie1.3) padc0 (eip1.3) programmable counter array 0x005b 11 cf (pca0cn.7) ccfn (pca0cn.n) y n epca0 (eie1.4) ppca0 (eip1.4) comparator0 0x0063 12 cp0fif (cpt0cn.4) cp0rif (cpt0cn.5) n n ecp0 (eie1.5) pcp0 (eip1.5) reserved 0x006b 13 timer 3 overflow 0x0073 14 tf3h (tmr3cn.7) tf3l (tmr3cn.6) n n et3 (eie1.7) pt3 (eip1.7) supply monitor early warning 0x007b 15 vddok (vdm0cn.5) 1 n n ewarn (eie2.0) pwarn (eip2.0) port match 0x0083 16 none emat (eie2.1) pmat (eip2.1) smartclock oscillator fail 0x008b 17 oscfail (rtc0cn.5) 2 n n ertc0f (eie2.2) pfrtc0f (eip2.2) reserved 0x0093 18 cs0 conversion complete 0x009b 19 cs0int (cs0cn.5) y n ecscpt (eie2.4) pcscpt (eip2.4) cs0 digital comparator 0x00a3 20 cs0cmpf (cs0cn.0) y n ecsdc (eie2.5) pcsdc (eip2.5) cs0 end of scan 0x00ab 21 cs0eos (cs0cn.6) y n ecseos (eie2.6) pcseos (eip2.6) notes: 1. indicates a read-only interrupt pending flag. the interrupt enable may be used to prevent software from vectoring to the associated interrupt service routine. 2. indicates a register located in an indirect memory space. www.datasheet.in
c8051f99x-c8051f98x 140 rev. 1.0 13.5. interrupt register descriptions the sfrs used to enable the interrupt sources and se t their priority level ar e described in the following register descriptions. refer to the data sheet sectio n associated with a particular on-chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s). www.datasheet.in
rev. 1.0 141 c8051f99x-c8051f98x sfr page = all; sfr address = 0xa8; bit-addressable sfr definition 13.1. ie: interrupt enable bit 7 6 5 4 3 2 1 0 name ea espi0 et2 es0 et1 ex1 et0 ex0 type r/w r/w r/w r/w r/w r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 ea enable all interrupts. globally enables/disables all interrupts. it ov errides individual interrupt mask settings. 0: disable all interrupt sources. 1: enable each interrupt according to its individual mask setting. 6 espi0 enable serial peripheral interface (spi0) interrupt. this bit sets the masking of the spi0 interrupts. 0: disable all spi0 interrupts. 1: enable interrupt requests generated by spi0. 5 et2 enable timer 2 interrupt. this bit sets the masking of the timer 2 interrupt. 0: disable timer 2 interrupt. 1: enable interrupt requests generated by the tf2l or tf2h flags. 4 es0 enable uart0 interrupt. this bit sets the masking of the uart0 interrupt. 0: disable uart0 interrupt. 1: enable uart0 interrupt. 3 et1 enable timer 1 interrupt. this bit sets the masking of the timer 1 interrupt. 0: disable all timer 1 interrupt. 1: enable interrupt requests generated by the tf1 flag. 2 ex1 enable external interrupt 1. this bit sets the masking of external interrupt 1. 0: disable external interrupt 1. 1: enable interrupt requests generated by the int1 input. 1 et0 enable timer 0 interrupt. this bit sets the masking of the timer 0 interrupt. 0: disable all timer 0 interrupt. 1: enable interrupt requests generated by the tf0 flag. 0 ex0 enable external interrupt 0. this bit sets the masking of external interrupt 0. 0: disable external interrupt 0. 1: enable interrupt requests generated by the int0 input. www.datasheet.in
c8051f99x-c8051f98x 142 rev. 1.0 sfr page = all; sfr address = 0xb8; bit-addressable sfr definition 13.2. ip: interrupt priority bit 7 6 5 4 3 2 1 0 name pspi0 pt2 ps0 pt1 px1 pt0 px0 type r r/w r/w r/w r/w r/w r/w r/w reset 1 0 0 0 0 0 0 0 bit name function 7 unused read = 1b, write = don't care. 6 pspi0 serial peripheral interface (spi 0) interrupt priority control. this bit sets the priority of the spi0 interrupt. 0: spi0 interrupt set to low priority level. 1: spi0 interrupt set to high priority level. 5 pt2 timer 2 interrupt priority control. this bit sets the priority of the timer 2 interrupt. 0: timer 2 interrupt set to low priority level. 1: timer 2 interrupt set to high priority level. 4 ps0 uart0 interrupt priority control. this bit sets the priority of the uart0 interrupt. 0: uart0 interrupt set to low priority level. 1: uart0 interrupt set to high priority level. 3 pt1 timer 1 interrupt priority control. this bit sets the priority of the timer 1 interrupt. 0: timer 1 interrupt set to low priority level. 1: timer 1 interrupt set to high priority level. 2 px1 external interrupt 1 priority control. this bit sets the priority of the external interrupt 1 interrupt. 0: external interrupt 1 se t to low priority level. 1: external interrupt 1 se t to high priority level. 1 pt0 timer 0 interrupt priority control. this bit sets the priority of the timer 0 interrupt. 0: timer 0 interrupt set to low priority level. 1: timer 0 interrupt set to high priority level. 0 px0 external interrupt 0 priority control. this bit sets the priority of the external interrupt 0 interrupt. 0: external interrupt 0 se t to low priority level. 1: external interrupt 0 se t to high priority level. www.datasheet.in
rev. 1.0 143 c8051f99x-c8051f98x sfr page = all; sfr address = 0xe6 sfr definition 13.3. eie1: extended interrupt enable 1 bit 7 6 5 4 3 2 1 0 name et3 ecp0 epca0 eadc0 ewadc0 ertc0a esmb0 type r/w r r/w r/w r/w r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 et3 enable timer 3 interrupt. this bit sets the masking of the timer 3 interrupt. 0: disable timer 3 interrupts. 1: enable interrupt requests generated by the tf3l or tf3h flags. 6 unused read = 0b. write = don?t care. 5 ecp0 enable comparator0 (cp0) interrupt. this bit sets the masking of the cp0 interrupt. 0: disable cp0 interrupts. 1: enable interrupt requests generated by the cp0rif or cp0fif flags. 4 epca0 enable programmable counte r array (pca0) interrupt. this bit sets the masking of the pca0 interrupts. 0: disable all pc a0 interrupts. 1: enable interrupt requests generated by pca0. 3 eadc0 enable adc0 conversion complete interrupt. this bit sets the masking of the adc0 conversion complete interrupt. 0: disable adc0 conversi on complete interrupt. 1: enable interrupt requests generated by the ad0int flag. 2 ewadc0 enable window comparison adc0 interrupt. this bit sets the masking of adc0 window comparison interrupt. 0: disable adc0 window comparison interrupt. 1: enable interrupt requests generated by adc0 window compare flag (ad0wint). 1 ertc0a enable smartclock alarm interrupts. this bit sets the masking of the smartclock alarm interrupt. 0: disable smartclo ck alarm interrupts. 1: enable interrupt requests generated by a smartclock alarm. 0 esmb0 enable smbus (smb0) interrupt. this bit sets the masking of the smb0 interrupt. 0: disable all smb0 interrupts. 1: enable interrupt requests generated by smb0. www.datasheet.in
c8051f99x-c8051f98x 144 rev. 1.0 sfr page = all; sfr address = 0xf6 sfr definition 13.4. eip1: extended interrupt priority 1 bit 7 6 5 4 3 2 1 0 name pt3 pcp0 ppca0 padc0 pwadc0 prtc0a psmb0 type r/w r r/w r/w r/w r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 pt3 timer 3 interrupt priority control. this bit sets the priority of the timer 3 interrupt. 0: timer 3 interrupts set to low priority level. 1: timer 3 interrupts set to high priority level. 6 unused read = 0b. write = don?t care. 5 pcp0 comparator0 (cp0) interru pt priority control. this bit sets the priority of the cp0 interrupt. 0: cp0 interrupt set to low priority level. 1: cp0 interrupt set to high priority level. 4 ppca0 programmable counter array (pca0) interrupt priority control. this bit sets the priority of the pca0 interrupt. 0: pca0 interrupt set to low priority level. 1: pca0 interrupt set to high priority level. 3 padc0 adc0 conversion complete interrupt priority control. this bit sets the priority of the adc0 conversion complete interrupt. 0: adc0 conversion complete inte rrupt set to low priority level. 1: adc0 conversion complete interrupt set to high priority level. 2 pwadc0 adc0 window comparator interrupt priority control. this bit sets the priority of the adc0 window interrupt. 0: adc0 window interrupt se t to low priority level. 1: adc0 window interrupt set to high priority level. 1 prtc0a smartclock alarm interr upt priority control. this bit sets the priority of the smartclock alarm interrupt. 0: smartclock alarm interrup t set to low priority level. 1: smartclock alarm interrupt set to high priority level. 0 psmb0 smbus (smb0) interrupt priority control. this bit sets the priority of the smb0 interrupt. 0: smb0 interrupt set to low priority level. 1: smb0 interrupt set to high priority level. www.datasheet.in
rev. 1.0 145 c8051f99x-c8051f98x sfr page = all;sfr address = 0xe7 sfr definition 13.5. eie2: extended interrupt enable 2 bit 7 6 5 4 3 2 1 0 name ecseos ecsdc ecscpt ertc0f emat ewarn type r/w r/w r/w r/w r r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 unused read = 0b. write = don?t care. 6 ecseos enable capacitive sense end of scan interrupt. 0: disable capacitive sense end of scan interrupt. 1: enable interrupt requests generated by cs0eos. 5 ecsdc enable capacitive sense digital comparator interrupt. 0: disable capacitive sense digital comparator interrupt. 1: enable interrupt requests generated by cs0cmpf. 4 ecscpt enable capacitive sense conversion complete interrupt. 0: disable capacitive sense co nversion comple te interrupt. 1: enable interrupt requests generated by cs0int. 3 unused read = 0b. write = don?t care. 2 ertc0f enable smartclock oscillator fail interrupt. this bit sets the masking of the smartclock alarm interrupt. 0: disable smartclock alarm interrupts. 1: enable interrupt requests generated by smartclock alarm. 1 emat enable port match interrupts. this bit sets the masking of the port match event interrupt. 0: disable all port match interrupts. 1: enable interrupt requests generated by a port match. 0 ewarn enable supply monitor early warning interrupt. this bit sets the masking of the supply monitor early warning interrupt. 0: disable the supply monitor early warning interrupt. 1: enable interrupt requests generated by the supply monitor. www.datasheet.in
c8051f99x-c8051f98x 146 rev. 1.0 sfr page = all; sfr address = 0xf7 sfr definition 13.6. eip2: extended interrupt priority 2 bit 7 6 5 4 3 2 1 0 name pcseos pcsdc pcscpt prtc0f pmat pwarn type r r/w r/w r/w r r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 unused read = 0b. write = don?t care. 6 pcseos capacitive sense end of scan interrupt priority control. 0: capacitive sense end of scan in terrupt set to lo w priority level. 1: capacitive sense end of scan in terrupt set to high priority level. 5 pcsdc capacitive sense digital comparator interrupt priority control. 0: capacitive sense digital comparator interrupt set to low priority level. 1: capacitive sense digital comparator interrupt set to high priority level. 4 pcscpt capacitive sense conversion complete interrupt priority control. 0: capacitive sense conversion complete interrupt set to low priority level. 1: capacitive sense conversion complete interrupt set to high priority level. 3 unused read = 0b. write = don?t care. 2 prtc0f smartclock oscillator fail in terrupt priority control. this bit sets the priority of the smartclock alarm interrupt. 0: smartclock alarm interrupt set to low priority level. 1: smartclock alarm interrupt set to high priority level. 1 pmat port match interrupt priority control. this bit sets the priority of the port match event interrupt. 0: port match interrupt se t to low priority level. 1: port match interrupt se t to high priority level. 0 pwarn supply monitor early warning interrupt priori ty control. this bit sets the priority of the supply monitor early warning interrupt. 0: supply monitor early warning in terrupt set to low priority level. 1: supply monitor early warning inte rrupt set to high priority level. www.datasheet.in
rev. 1.0 147 c8051f99x-c8051f98x 13.6. external interrupts int0 and int1 the int0 and int1 external interrupt sources are configurable as active high or low, edge or level sensitive. the in0pl ( int0 polarity) and in1pl ( int1 polarity) bits in the it01cf register select active high or active low; the it0 and it1 bits in tcon ( section ?25.1. timer 0 and timer 1? on page 278 ) select level or edge sensitive. the table be low lists the possible configurations. int0 and int1 are assigned to port pins as defined in the it01cf register (see sfr definition 13.7 ). note that int0 and int0 port pin assignments are independent of any crossbar assignments. int0 and int1 will monitor their assigned port pins wit hout disturbing the peripheral that was assigned the port pin via the crossbar. to assign a port pin only to int0 and/or int1 , configure the crossbar to skip the selected pin(s). this is accomplished by setting the associated bit in register xbr0 (see section ?21.3. priority crossbar decoder? on page 217 for complete details on configuring the crossbar). ie0 (tcon.1) and ie1 (tcon.3) serve as the interrupt-pending flags for the int0 and int1 external interrupts, respectively. if an int0 or int1 external interrupt is configured as edge-sensitive, the corresponding interrupt-pending flag is automatically cleared by the hardware when the cpu vectors to the isr. when configured as level sensitiv e, the interrupt-pending flag remains logic 1 while the input is active as defined by the corresponding pola rity bit (in0pl or in1pl); the flag remains logic 0 while the input is inactive. the external interrupt source must hold the i nput active until the interrupt request is recognized. it must then deactivate the interrup t request before execution of the isr completes or another interrupt request will be generated. it0 in0pl int0 interrupt it1 in1pl int1 interrupt 10 active low, edge sensitive 10 active low, edge sensitive 11 active high, edge sensitive 11 active high, edge sensitive 00 active low, level sensitive 00 active low, level sensitive 01 active high, level sensitive 01 active high, level sensitive www.datasheet.in
c8051f99x-c8051f98x 148 rev. 1.0 sfr page = 0x0; sfr address = 0xe4 sfr definition 13.7. it01cf: int0 / int1 configuration bit 7 6 5 4 3 2 1 0 name in1pl in1sl[2:0] in0pl in0sl[2:0] type r/w r/w r/w r/w reset 0 0 0 0 0 0 0 1 bit name function 7 in1pl int1 polarity. 0: int1 input is active low. 1: int1 input is active high. 6:4 in1sl[2:0] int1 port pin se lection bits. these bits select which port pin is assigned to int1 . note that this pin assignment is independent of the crossbar; int1 will monitor the assigned port pin without disturb - ing the peripheral that has been assigned t he port pin via the crossbar. the crossbar will not assign the port pin to a peripheral if it is configured to skip the selected pin. 000: select p0.0 001: select p0.1 010: select p0.2 011: select p0.3 100: select p0.4 101: select p0.5 110: select p0.6 111: select p0.7 3 in0pl int0 polarity. 0: int0 input is active low. 1: int0 input is active high. 2:0 in0sl[2:0] int0 port pin se lection bits. these bits select which port pin is assigned to int0 . note that this pin assignment is independent of the crossbar; int0 will monitor the assigned port pin without disturb - ing the peripheral that has been assigned t he port pin via the crossbar. the crossbar will not assign the port pin to a peripheral if it is configured to skip the selected pin. 000: select p0.0 001: select p0.1 010: select p0.2 011: select p0.3 100: select p0.4 101: select p0.5 110: select p0.6 111: select p0.7 www.datasheet.in
rev. 1.0 149 c8051f99x-c8051f98x 14. flash memory on-chip, re-programmable flash memory is included fo r program code and non-volatile data storage. the flash memory can be programmed in-system through the c2 interface or by software using the movx write instruction. once cleared to logic 0, a flash bit must be erased to set it back to logic 1. flash bytes would typically be erased (set to 0xff) before be ing reprogrammed. the write and erase operations are automatically timed by hard ware for proper execution; data polling to determine the end of th e write/erase operations is not required. code execution is sta lled during flash write/erase operations. refer to ta b l e 4.6 for complete flas h memory electrical characteristics. 14.1. programming the flash memory the simplest means of programming the flash memory is through the c2 interface using programming tools provided by silicon laboratories or a th ird party vendor. this is the only means for programming a non-initialized device. for details on the c2 commands to program flash memory, see section ?27. c2 interface? on page 317 . the flash memory can be programmed by software using the movx write instruction with the address and data byte to be programmed provided as normal operands. before programming flash memory using movx, flash programming operations must be enabled by: (1) setting the pswe program store write enable bit (psctl.0) to logic 1 (this directs the movx writes to target flash memory); and (2) writing the flash key codes in sequence to the flash lock regist er (flkey). the pswe bit remains set until cleared by software. for detailed guidelines on programming flash from firmware, please see section ?14.5. flash write and erase guidelines? on page 155 . to ensure the integrity of the flash contents, the on -chip vdd monitor must be enabled and enabled as a reset source in any system that includes code that writes and/or erases flash memory from software. fur - thermore, there should be no delay between enabling the v dd monitor and enabling the v dd monitor as a reset source. any attempt to write or erase flash memory while the v dd monitor is disabled, or not enabled as a reset source, will ca use a flash error device reset. 14.1.1. flash lock and key functions flash writes and erases by user so ftware are protected with a lock and key function. th e flash lock and key register (flkey) must be writ ten with the correct key codes, in sequence, be fore flash operations may be performed. the key codes are: 0xa5, 0xf1. the timing does not matter, but the codes must be written in order. if the key codes are written out of or der, or the wrong codes are written, flash writes and erases will be disabled until the next system reset. flash writes and eras es will also be disabled if a flash write or erase is attempted before the key codes have been written properly. the flash lock resets after each write or erase; the key codes must be writte n again before a following flash operation can be per - formed. the flkey regist er is detailed in sfr definition 14.4 . www.datasheet.in
c8051f99x-c8051f98x 150 rev. 1.0 14.1.2. flash erase procedure the flash memory is organized in 512-byte pages. the erase operation applies to an entire page (setting all bytes in the page to 0xff). to erase an entire flash page, perform the following steps: 1. save current interrupt state and disable interrupts. 2. set the psee bit (register psctl). 3. set the pswe bit (register psctl). 4. write the first key code to flkey: 0xa5. 5. write the second key code to flkey: 0xf1. 6. using the movx instruction, wr ite a data byte to any location within the page to be erased. 7. clear the pswe and psee bits. 8. restore previous interrupt state. steps 4?6 must be repeated for each 512-byte page to be erased. notes: 1. flash security settings may prevent erasure of some flash pages, such as the reserved area and the page containing the lock bytes. for a summary of flash security settings and restrictions affecting flash erase operations, please see section ?14.3. security options? on page 151 . 2. 8-bit movx instructions cannot be used to erase or wr ite to flash memory at addresses higher than 0x00ff. 14.1.3. flash write procedure a write to flash memory can clear bits to logic 0 but cannot set them; only an erase operation can set bits to logic 1 in flash. a byte location to be programmed should be erased before a new value is written. the recommended procedure for writing a si ngle byte in flash is as follows: 1. save current interrupt state and disable interrupts. 2. ensure that the flash byte has been erased (has a value of 0xff). 3. set the pswe bit (register psctl). 4. clear the psee bit (register psctl). 5. write the first key code to flkey: 0xa5. 6. write the second key code to flkey: 0xf1. 7. using the movx instruction, write a single data byte to the desired lo cation within the 1024-byte sector. 8. clear the pswe bit. 9. restore previous interrupt state. steps 5?7 must be repeated for each byte to be written. notes: 1. flash security settings may prevent writes to some ar eas of flash, such as the reserved area. for a summary of flash security settings and restrictions affecting flash write operations, please see section ?14.3. security options? on page 151 . 2. 8-bit movx instructions cannot be used to erase or wr ite to flash memory at addresses higher than 0x00ff. 14.2. non-volatile data storage the flash memory can be used for non-volatile data storage as well as program code. this allows data such as calibration coefficients to be calculated and stored at run time. data is written using the movx write instruction and read using th e movc instruction. movx read instructions always target xram. www.datasheet.in
rev. 1.0 151 c8051f99x-c8051f98x 14.3. security options the cip-51 provides security options to protect the flash memory from inadvertent modification by soft - ware as well as to prevent the viewing of proprietary program code and constants. the program store write enable (bit pswe in register psctl) and the program store erase enable (bit psee in register psctl) bits protect the flash memory from accidental modification by software. pswe must be explicitly set to 1 before software can modify the flash memo ry; both pswe and psee must be set to 1 before soft - ware can erase flash memory. additional security features prevent proprietary program code and data constants from being read or altered across the c2 interface. a security lock byte located at the last byte of fl ash user space offers protection of the flash program memory from access (reads, writes, or erases) by unprotected code or the c2 interface. see section ?10. memory organization? on page 127 for the location of the security byte. the flash security mecha - nism allows the user to lock n 512-byte flash pages, starting at p age 0 (addresses 0x0000 to 0x01ff), where n is the 1s complement number repres ented by the security lock byte. the page containing the flash security lock byte is unlocked when no othe r flash pages are locked (all bits of the lock byte are 1) and locked when any other flash pages are locked (any bit of the lock byte is 0). figure 14.1. flash program memory map (8 kb and smaller devices) the level of flash security depends on the flash ac cess method. the three flash access methods that can be restricted are reads, writes, an d erases from the c2 debug interface, user firmware executing on unlocked pages, and user firmware executing on locked pages. ta b l e 14.1 summarizes the flash security features of the c8051f99x-c8051f98x devices. security lock byte: 1111 1011b ones complement: 0000 0100b flash pages locked: 5 (first four flash pages + lock byte page) lock byte page access limit set according to the flash security lock byte lock byte unlocked flash pages locked when any other flash pages are locked lock byte page lock byte reserved unlocked flash pages 8kb flash device 4 or 2 kb flash device reserved www.datasheet.in
c8051f99x-c8051f98x 152 rev. 1.0 table 14.1. flash security summary action c2 debug interface user firmware executing from: an unlocked page a locked page read, write or erase unlocked pages (except page with lock byte) permitted permitted permitted read, write or erase locked pages (except page with lock byte) not permitted fedr permitted read or write page containing lock byte (if no pages are locked) permitted permitted permitted read or write page containing lock byte (if any page is locked) not permitted fedr permitted read contents of lock byte ? (if no pages are locked) permitted permitted permitted read contents of lock byte ? (if any page is locked) not permitted fedr permitted erase page containing lock byte (if no pages are locked) permitted fedr fedr erase page containing lock byte?unlock all pages (if any page is locked) only by c2de fedr fedr lock additional pages (change 1s to 0s in the lock byte) not permitted fedr fedr unlock individual pages ? (change 0s to 1s in the lock byte) not permitted fedr fedr read, write or erase reserved area not permitted fedr fedr ? c2de?c2 device erase (erases all flash pages including the page containing the lock byte) ? fedr?not permitted; causes flash error device reset (ferror bit in rs tsrc is 1 after reset) ? all prohibited operations that are performed via th e c2 interface are ignored (do not cause device reset). ? locking any flash page also locks the page containing the lock byte. ? once written to, the lock byte cannot be modifi ed except by performing a c2 device erase. ? if user code writes to the lock byte, the lock does not take effect until the next device reset. ? the scratchpad is locked when all other flash pages are locked. ? the scratchpad is erased when a flash device erase command is performed. www.datasheet.in
rev. 1.0 153 c8051f99x-c8051f98x 14.4. determining the device part number at run time in many applications, user software may need to determine the mcu part number at run time in order to determine the hardware capabilities. the part number can be determi ned by reading the value of the deviceid special function register. ? ? the value of the deviceid regi ster can be decoded as follows: ? ? 0xd0?c8051f990 ? 0xd1?c8051f991 ? 0xd6?c8051f996 ? 0xd2?c8051f997 ? ? 0xd3?C8051F980 ? 0xd4?c8051f981 ? 0xd5?c8051f982 ? 0xd7?c8051f983 ? 0xd8?c8051f985 ? 0xd9?c8051f986 ? 0xda?c8051f987 ? 0xdb?c8051f988 ? 0xdc?c8051f989 ? sfr page = 0xf; sfr address = 0xe3 sfr definition 14.1. deviceid: device identification bit 7 6 5 4 3 2 1 0 name deviceid[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 deviceid[7:0] device identification. these bits contain a value that can be decoded to determine the device part number. www.datasheet.in
c8051f99x-c8051f98x 154 rev. 1.0 sfr page = 0x0f; sfr address = 0xe2 sfr definition 14.2. revid: revision identification bit 7 6 5 4 3 2 1 0 name revid[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 revid[7:0] revision identification. these bits contain a value that can be decoded to deter mine the silicon ? revision. for example, 0x00 for rev a and 0x01 for rev b, etc. www.datasheet.in
rev. 1.0 155 c8051f99x-c8051f98x 14.5. flash write and erase guidelines any system which contains routines which write or er ase flash memory from software involves some risk that the write or erase ro utines will execute unin tentionally if the cpu is op erating outside its specified operating range of v dd , system clock frequency, or temperature. this accidental execution of flash modi - fying code can result in alteration of flash memory contents causing a system failure that is only recover - able by re-flashing the code in the device. to help prevent the accidental modifi cation of flash by firmware, the v dd monitor must be enabled and enabled as a reset source on c8051f99x-c8051f98x devices for the flash to be successfully modified. if either the v dd monitor or the v dd monitor reset source is not enabled, a flash error device reset will be generated when the firmwar e attempts to modify the flash. the following guidelines are recomme nded for any system that contains routines which write or erase flash from code. 14.5.1. v dd maintenance and the v dd monitor 1. if the system power supply is subject to voltage or current "spikes," add sufficient transient protection devices to the power supply to ensure that the supply voltages listed in the absolute maximum ratings table are not exceeded. 2. make certain that the minimum v dd rise time specification of 1 ms is met. if the system cannot meet this rise time specificati on, then add an external v dd brownout circuit to the rst pin of the device that holds the device in reset until v dd reaches the minimum device operating voltage and re-asserts rst if v dd drops below the minimum device operating voltage. 3. keep the on-chip v dd monitor enabled and enable the v dd monitor as a reset source as early in code as possible. this should be the fi rst set of instructions executed after the reset vector. for c-based systems, this will involve modifyin g the startup code a dded by the c compiler. see your compiler documentation for more details. make certain that th ere are no delays in software between enabling the v dd monitor and enabling the v dd monitor as a reset source. code examples showing this can be found in ?an201: writing to flash from firmware," available from the silicon laboratories website. ? notes: 1. on c8051f99x-c8051f98x devices, both the v dd monitor and the v dd monitor reset source must be enabled to write or erase flash without generating a flash error device reset. 2. on c8051f99x-c8051f98x devices, both the v dd monitor and the v dd monitor reset source are enabled by hardware after a power-on reset. 4. as an added precaution, explicitly enable the v dd monitor and enable the v dd monitor as a reset source inside the functions that write and erase flash memory. the v dd monitor enable instructions should be placed just after the in struction to set pswe to a 1, but before the flash write or erase operation instruction. 5. make certain that all writes to the rstsrc (reset sources) register use di rect assignment operators and explicitly do not use the bit-wise operators (such as and or or). for example, "rstsrc = 0x02" is correct, but "rstsrc |= 0x02" is incorrect. 6. make certain that all writes to the rstsrc register explicitly set the porsf bi t to a 1. areas to check are initialization code which enab les other reset sources, such as the missing clock detector or comparator, for example, and instructions which force a software reset. a global search on "rstsrc" can quickly verify this. www.datasheet.in
c8051f99x-c8051f98x 156 rev. 1.0 14.5.2. pswe maintenance 1. reduce the number of places in code where the pswe bit (b0 in psctl) is set to a 1. there should be exactly one routine in code that sets pswe to a 1 to write flash bytes and one routine in code that sets both pswe and psee both to a 1 to erase flash pages. 2. minimize the number of variable accesses while pswe is set to a 1. handle pointer address updates and loop maintenance outside the "pswe = 1;... pswe = 0;" area. code examples showing this can be found in :an201: " writing to flash from firmwa re", available from the s ilicon laboratories website. 3. disable interrupts prior to setting pswe to a 1 and leave them disabled until after pswe has been reset to 0. any inte rrupts posted during the flash write or er ase operation will be serviced in priority order after the flash operation has been completed a nd interrupts have been re-enabled by software. 4. make certain that the flash write and erase poin ter variables are not located in xram. see your compiler documentation for instructions regarding how to explicitly locate variab les in different memory areas. 5. add address bounds checking to th e routines that write or erase flas h memory to ensure that a routine called with an illegal address does not result in modification of the flash. 14.5.3. system clock 1. if operating from an external crystal, be advised th at crystal performance is susceptible to electrical interference and is sensitive to layout and to changes in temperature. if the system is operating in an electrically noisy environment, use the internal oscillator or use an external cmos clock. 2. if operating from the external oscillator, switch to the internal oscillator du ring flash write or erase operations. the external oscillator can continue to run, and the cpu can switch back to the external oscillator after the flash operation has completed. ? additional flash recommendations and example code ca n be found in ?an201: writing to flash from firm - ware", available from the s ilicon laboratories web site. www.datasheet.in
rev. 1.0 157 c8051f99x-c8051f98x 14.6. minimizing flash read current the flash memory in the c8051f99x-c8051f98x devices is responsible for a substantial portion of the total digital supply current when the device is execut ing code. below are suggestions to minimize flash read current. 1. use idle, suspend, or sleep modes while waiting for an inte rrupt, rather than po lling the interrupt flag. idle mode is particularly well-suited for use in implementing short pauses, since the wake-up time is no more than three system clock cycles. see the power management chapter for details on the various low-power operating modes. 2. c8051f99x-c8051f98x devices have a one-shot ti mer that saves power when operating at system clock frequencies of 14 mhz or less. the one-shot timer generates a minimum-duration enable signal for the flash sense amps on each clock cycle in wh ich the flash memory is accessed. this allows the flash to remain in a low power state for the remainder of the long clock cycle. ? at clock frequencies above 14 mhz, the system clock cycle becomes short enough that the one-shot timer no longer provides a power benefit. disabling the one-shot timer at higher frequencies reduces power consumption. the one-shot is enabled by def ault, and it can be disabled (bypassed) by setting the bypass bit (flscl.6) to logic 1. to re-enable the one-shot, clear the bypass bit to logic 0. 3. flash read current depends on the number of addre ss lines that toggle between sequential flash read operations. in most cases, the difference in power is relatively small (on the order of 5%). ? ? the flash memory is organized in rows of 64 byte s. a substantial current increase can be detected when the read address jumps from one row in the flash memory to another. consider a 3-cycle loop (e.g., sjmp $, or while(1);) which straddles a flash row boundary. the flash address jumps from one row to another on two of every three clock cycles. this can result in a current increase of up 30% when compared to the same 3-cycle loop contained entirely within a single row. ? ? to minimize the power consumption of small loops, it is best to locate them within a single row, if possible. to check if a loop is contained within a fl ash row, divide the starting address of the first instruction in the loop by 64. if t he remainder (result of modulo operatio n) plus the length of the loop is less than 63, then the loop fits inside a single flash row. other wise, the loop will be straddling two adjacent flash rows. if a loop executes in 20 or mo re clock cycles, then the tr ansitions from one row to another will occur on relatively few clock cycles, and any resulting in crease in operating current will be negligible. www.datasheet.in
c8051f99x-c8051f98x 158 rev. 1.0 sfr page =all; sfr address = 0x8f sfr definition 14.3. psctl: program store r/w control bit 7 6 5 4 3 2 1 0 name psee pswe type r r r r r r r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7:2 unused read = 000000b, write = don?t care. 1 psee program store erase enable. setting this bit (in combination with pswe) allows an entire page of flash program memory to be erased. if this bit is logic 1 and flash writes are enabled (pswe is logic 1), a write to flash memory using the movx instruction will erase the entire page that contains the location addressed by the movx instruction. the value of the data byte written does not matter. 0: flash program memory erasure disabled. 1: flash program memory erasure enabled. 0 pswe program store write enable. setting this bit allows writing a byte of data to the flash program memory using the movx write instruction. the flash location should be erased before writing data. 0: writes to flash program memory disabled. 1: writes to flash program memory enabl ed; the movx write instruction targets flash memory. www.datasheet.in
rev. 1.0 159 c8051f99x-c8051f98x sfr page = all; sfr address = 0xb7 sfr definition 14.4. flkey: flash lock and key bit 7 6 5 4 3 2 1 0 name flkey[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 flkey[7:0] flash lock and key register. write: this register provides a lock and key func tion for flash erasures and writes. flash writes and erases ar e enabled by writing 0xa5 follo wed by 0xf1 to the flkey regis - ter. flash writes and erases are automatically disabled after the next write or erase is complete. if any writes to flkey are performed incorrectly, or if a flash write or erase operation is attempted while these operations are disa bled, the flash will be perma - nently locked from writes or erasures unt il the next device reset. if an application never writes to flash, it can intentionally lock the flash by writing a non-0xa5 value to flkey from software. read: when read, bits 1?0 indicate the current flash lock state. 00: flash is write/erase locked. 01: the first key code has been written (0xa5). 10: flash is unlocked (writes/erases allowed). 11: flash writes/erases disabled until the next reset. www.datasheet.in
c8051f99x-c8051f98x 160 rev. 1.0 sfr page = all; sfr address = 0xb7 sfr page = all; sfr address = 0xe5 sfr definition 14.5. flscl: flash scale bit 7 6 5 4 3 2 1 0 name bypass type r r/w r r r r r r reset 0 0 0 0 0 0 0 0 bit name function 7 reserved always write to 0. 6 bypass flash read timing one-shot bypass. 0: the one-shot determines t he flash read time. this setting should be used for oper - ating frequencies less than 14 mhz. 1: the system clock determines the flash read time. this setting should be used for frequencies greater than 14 mhz. 5:0 reserved reserved. always write to 000000. note: operations which clear the bypass bit do not need to be immediately followed by a benign 3-byte instruction. for code compatibility with c8051f930/31/20/21 devices, a benign 3-byte instruction whose third byte is a don't care should follow the clear operation. see the c8051f93x-c8051f92x data sheet for more details. sfr definition 14.6. flwr: flash write only bit 7 6 5 4 3 2 1 0 name flwr[7:0] type w reset 0 0 0 0 0 0 0 0 bit name function 7:0 flwr[7:0] flash write only. all writes to this register have no effect on system operation. www.datasheet.in
rev. 1.0 161 c8051f99x-c8051f98x 15. power management c8051f99x-c8051f98x devices support 5 power modes: normal, idle, stop, suspend, and sleep. the power management unit (pmu0) allows the device to enter and wake-up from the available power modes. a brief description of each power mode is provided in ta b l e 15.1 . detailed descriptions of each mode can be found in the following sections. in battery powered systems, the system should spend as much time as possible in sleep mode in order to preserve battery life. when a task with a fixed number of clock cycles needs to be performed, the device should switch to normal mode, finish the task as quickly as possible, and return to sleep mode. idle mode and suspend modes provide a very fa st wake-up time; however, the power savings in these modes will not be as much as in sleep mode. stop mode is included for legacy reas ons; the system will be more power efficient and easier to wake up when idle, suspend, or sleep mode are used. although switching power modes is an integral part of power management, enabling/disabling individual peripherals as needed will help lower power consumption in all power modes. each analog peripheral can be disabled when not in use or placed in a low power mode. digital peripherals such as timers or serial busses draw little power whenever they are not in us e. digital peripherals draw no power in sleep mode. table 15.1. power modes power mode description wake-up sources power savings normal device fully functional n/a excellent mips/mw idle all peripherals fully functional. very easy to wake up. any interrupt good no code execution stop legacy 8051 low power mode. a reset is required to wake up. any reset good no code execution precision oscillator disabled suspend similar to stop mode, but very fast wake-up time and code resumes execution at the next instruction. cs0, smartclock, port match, comparator0, rst pin very good no code execution all internal oscillators disabled system clock gated sleep ultra low power and flexible wake-up sources. code resumes execution at the next instruction. comparator0 only functional in two-cell mode. smartclock, port match, comparator0, rst pin excellent power supply gated all oscillators except smart - clock disabled www.datasheet.in
c8051f99x-c8051f98x 162 rev. 1.0 15.1. normal mode the mcu is fully functional in normal mode. figure 15.1 shows the on-chip power distribution to various peripherals. there are two supply voltages powering various sections of the chip: v dd and the 1.8 v inter - nal core supply. all analog peripherals are directly powered from the v dd pin. all digital peripherals and the cip-51 core are powered from the 1.8 v internal core supply. ram, pmu0 and the smartclock are always powered directly from the vbat pin in sleep mo de and powered from the core supply in all other power modes. figure 15.1. c8051f99x-c8051f98x power distribution ram vreg0 pmu0 sleep active/idle/ stop/suspend vdd 1.8 to 3.6 v analog peripherals adc temp sensor a m u x voltage comparator iref0 + - vref digital peripherals flash cip-51 core uart spi smbus timers gpio 1.8 v smartclock www.datasheet.in
rev. 1.0 163 c8051f99x-c8051f98x 15.2. idle mode setting the idle mode select bit (pcon.0) causes the cip-51 to halt the cpu and enter idle mode as soon as the instruction that sets the bit completes executio n. all internal registers and memory maintain their original data. all analog and digital peripherals can remain active during idle mode. note: to ensure the mcu enters a low power state upon entry in to idle mode, the one-shot circuit should be enabled by clearing the bypass bit (flscl.6). idle mode is terminated when an enabled interrupt is asserted or a reset occurs. the assertion of an enabled interrupt will cause the idle mode selection bit (pcon.0) to be cleared and the cpu to resume operation. the pen ding interrupt will be serviced and the next in struction to be executed after the return from interrupt (reti) will be the instruction immedi ately following the one that se t the idle mode select bit. if idle mode is terminated by an internal or external reset, the cip-51 performs a normal reset sequence and begins program execution at address 0x0000. if enabled, the watchdog timer (wdt) will eventually cause an internal watchdog reset and thereby termi - nate the idle mode. this feature protects the system from an unintended permanent shutdown in the event of an inadvertent write to the pcon register. if this behavior is not desired, th e wdt may be disabled by software prior to entering th e idle mode if the wdt was initially config ured to allow this operation. this pro - vides the opportunity for additional power savings, allo wing the system to remain in the idle mode indefi - nitely, waiting for an external stimulus to wake up the system. refer to section ?18.6. pca watchdog timer reset? on page 183 for more information on the use and configuration of the wdt. 15.3. stop mode setting the stop mode select bit (pcon.1) causes th e cip-51 to enter stop mode as soon as the instruc - tion that sets the bit co mpletes execution. in stop mode the pr ecision internal o scillator and cpu are stopped; the state of the low power oscillator and the exte rnal oscillator circuit is not affected. each analog peripheral (including the external oscillator circuit) may be shut do wn individually prior to entering stop mode. stop mode can only be terminated by an internal or external reset. on re set, the cip-51 performs the normal reset sequence and begins program execution at address 0x0000. if enabled, the missing clock detect or will cause an internal reset and ther eby terminate th e stop mode. the missing clock detector should be disabled if the cpu is to be put to in stop mode for longer than the mcd timeout. stop mode is a legacy 8051 power mo de; it will not result in optimal power savings. sleep or suspend mode will provide more power savings if the mcu need s to be inactive for a long period of time. note: to ensure the mcu enters a low power state upon entry in to stop mode, the one-shot circuit should be enabled by clearing the bypass bit (flscl.6). www.datasheet.in
c8051f99x-c8051f98x 164 rev. 1.0 15.4. suspend mode setting the suspend mode select bit (pmu0cf.6) causes the system clock to be gated off and all internal oscillators disabled. the system cloc k source must be set to the low po wer internal oscillator or the preci - sion oscillator prior to entering susp end mode. all digital logic (timers, communication pe ripherals, inter - rupts, cpu, etc.) stops func tioning until one of the enabled wake-up sources occurs. the following wake-up sources can be configured to wake the device from suspend mode: ? cs0 end of conversion or end of scan ? smartclock oscillator fail ? smartclock alarm ? port match event ? comparator0 rising edge note: upon wake-up from suspend mode, pmu0 requires tw o system clocks in order to update the pmu0cf wake- up flags. all flags will read back a value of '0' during the first two system clocks following a wake-up from suspend mode. in addition, a noise glitch on rst that is not long enough to reset the device will cause the device to exit suspend. in order for the mcu to respond to the pin reset event, software must not place the device back into suspend mode for a period of 15 s. the pmu0cf register may be checked to determine if the wake- up was due to a falling edge on the /rst pin. if the wake-up source is not due to a falling edge on rst , there is no time restriction on how soon software may place the device back into suspend mode. a 4.7 kw pullup resistor to vdd is recommend for rst to prevent no ise glitches from waking the device. 15.5. sleep mode setting the sleep mode select bit (pmu0cf.7) turns off the internal 1.8 v regulator (vreg0) and switches the power supply of all on-chip ram to the vdd pin (see figure 15.1 ). power to most digital logic on the chip is disconnected; only pmu0 and the smartclock remain powered. analog peripherals remain pow - ered in two-cell mode. only the comparators remain functional when the device enters sleep mode. all other analog peripherals (cs0, adc0, iref0, external oscillato r, etc.) should be disabled prior to entering sleep mode. the system clock source must be set to the low power internal osc illator or the precision oscillator prior to entering sleep mode. gpio pins configured as digital outputs will retain thei r output state du ring sleep mode. in two-cell mode, they will maintain the same current drive capabilit y in sleep mode as they have in normal mode. gpio pins configured as digital inputs can be used during sleep mode as wakeup sources using the port match feature. in two-cell mode, they will maintain the same input leve l specs in sleep mode as they have in normal mode. ?c8051f99x-c8051f98x devices support a wakeup request for external devices. upon exit from sleep mode, the wake-up request signal is driven low, allowin g other devices in the system to wake up from their low power modes. ram and sfr register contents are preserved in sleep mode as long as the voltage on vbat does not fall below v por . the pc counter and all other volatile state information is preserved allowing the device to resume code execution upon waking up from sleep mode. www.datasheet.in
rev. 1.0 165 c8051f99x-c8051f98x the following wake-up sources can be configured to wake the device from sleep mode: ? smartclock oscillator fail ? smartclock alarm ? port match event ? comparator0 rising edge the comparator requires a supply voltage of at least 1.8 v to operate properly. on c8051f99x-c8051f98x devices, the por supply monitor can be disabled to save power by writing 1 to the mondis (pmu0md.5) bit. when the por supply monitor is disabled, all rese t sources will trigger a full por and will re-enable the por supply monitor. in addition, any falling edge on rst (due to a pin reset or a noise glit ch) will cause the device to exit sleep mode. in order for the mcu to respond to the pin reset event, software must not place the device back into sleep mode for a period of 15 s. the pmu0cf register may be checke d to determine if the wake-up was due to a falling edge on the rst pin. if the wake-up source is not due to a falling edge on rst , there is no time restriction on how soon software may place the device back into sleep mode. a 4.7 k ? pullup resistor to vdd is recommend for rst to prevent noise glitches from waking the device. 15.6. configuring wakeup sources before placing the device in a low power mode, one or more wakeup sources should be enabled so that the device does not remain in the lo w power mode indefinitely. for idle mode, this includes enabling any interrupt. for stop mode, this includes enabling any reset source or relying on the rst pin to reset the device. wake-up sources for suspend and sleep modes are configured through the pmu0cf register. wake-up sources are enabled by writing 1 to the corresponding wake-up source enable bit. wake-up sources must be re-enabled each time the device is placed in susp end or sleep mode, in the same write that places the device in the low power mode. the reset pin is always enabled as a wa ke-up source. on the falling edge of rst , the device will be awaken from sleep mode. the device must remain awake for more than 15 s in order for the reset to take place. 15.7. determining the event that caused the last wakeup when waking from idle m ode, the cpu will vector to th e interrupt which caused it to wake up. when wak - ing from stop mode, the rstsrc register may be read to determine the cause of the last reset. upon exit from suspend or sleep mode, the wake-up flags in the pmu0cf and pmu0fl registers can be read to determine the even t which caused the device to wake up . after waking up, the wake-up flags will continue to be updated if any of the wake-up events o ccur. wake-up flags are always updated, even if they are not enabled as wake-up sources. all wake-up flags enabled as wake-up sources in pmu0cf and pmu0fl must be cleared before the device can enter suspend or sleep mode. after clearing the wake-up flags, each of the enabled wake-up events should be checked in the individual peripheral s to ensure that a wake-up event did not occur while the wake-up flags were being cleared. www.datasheet.in
c8051f99x-c8051f98x 166 rev. 1.0 sfr page = 0x0; sfr address = 0xb5 sfr definition 15.1. pmu0cf: power management unit configuration 1,2,3 bit 7 6 5 4 3 2 1 0 name sleep suspend clear rstwk rtcfwk rtcawk pmatwk cpt0wk type w w w r r/w r/w r/w r/w reset 0 0 0 varies varies varies varies varies bit name description write read 7 sleep sleep mode select writing 1 places the device in sleep mode. n/a 6 suspend suspend mode select writing 1 places the device in suspend mode. n/a 5 clear wake-up flag clear writing 1 clears all wake- up flags. n/a 4 rstwk reset pin wake-up flag n/a set to 1 if a glitch has been detected on rst . 3 rtcfwk smartclock oscillator fail wake-up source enable and flag 0: disable wake-up on smartclock osc. fail. 1: enable wake-up on smartclock osc. fail. set to 1 if the smart - clock oscillator has failed. 2 rtcawk smartclock alarm wake-up source enable and flag 0: disable wake-up on smartclock alarm. 1: enable wake-up on smartclock alarm. set to 1 if a smartclock alarm has occurred. 1 pmatwk port match wake-up source enable and flag 0: disable wake-up on port match event. 1: enable wake-up on ? port match event. set to 1 if a port match event has occurred. 0 cpt0wk comparator0 wake-up source enable and flag 0: disable wake-up on comparator0 rising edge. 1: enable wake-up on comparator0 rising edge. set to 1 if comparator0 rising edge caused the last wake-up. notes: 1. read-modify-write operations (orl, anl, etc.) should not be used on this register. wake-up sources must be re-enabled each time the sleep or suspend bits are written to 1. 2. the low power internal osc illator cannot be disabled and the mcu cannot be pl aced in suspend or sleep mode if any wake-up flags are set to 1. software should clear all wake-up sources after each reset and after each wake-up from suspend or sleep modes. 3. pmu0 requires two system clocks to update the wake-up source flags after waking from suspend mode. the wake-up source flags will read ?0? during the first tw o system clocks following the wake from suspend mode. www.datasheet.in
rev. 1.0 167 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xce sfr definition 15.2. pmu0fl: power management unit flag 1,2 bit 7 6 5 4 3 2 1 0 name cs0wk type rr rrrrrr/w reset 00 00000varies bit name description write read 7:1 unused unused don?t care. 0000000 0 cs0wk cs0 wake-up source enable and flag 0: disable wake-up on cs0 event. 1: enable wake-up on cs0 event. set to 1 if cs0 event caused the last wake-up. notes: 1. the low power internal osc illator cannot be disabled and the mcu cannot be pl aced in suspend or sleep mode if any wake-up flags are set to 1. software should clear all wake-up sources after each reset and after each wake-up from suspend or sleep modes. 2. pmu0 requires two system clocks to update the wake-up source flags after waking from suspend mode. the wake-up source flags will read ?0? during the first tw o system clocks following the wake from suspend mode. www.datasheet.in
c8051f99x-c8051f98x 168 rev. 1.0 sfr page = 0xf; sfr address = 0xce sfr definition 15.3. pmu0md: power management unit mode bit 7 6 5 4 3 2 1 0 name rtcoe wakeoe mondis type r/w r/w r/w r/w r/w r/w r/w r/w reset 00 000000 bit name function 7 rtcoe buffered smartclock output enable. enables the buffered smartclo ck oscillator output on p0.2. 0: buffered smartclock output not enabled. 1: buffered smartclock output not enabled. 6 wakeoe wakeup request output enable. enables the sleep mode wake-up request signal on p0.3. 0: wake-up request signal is not enabled. 1: wake-up request signal is enabled. 5 mondis por supply monitor disable. writing a 1 to this bit disables the por supply monitor. 4:0 unused read = 00000b. write = don?t care. www.datasheet.in
rev. 1.0 169 c8051f99x-c8051f98x sfr page = all; sfr address = 0x87 15.8. power management specifications see ta b l e 4.5 on page 56 for detailed power management specifications. sfr definition 15.4. pcon: power manageme nt control register bit 7 6 5 4 3 2 1 0 name gf[5:0] stop idle type r/w w w reset 00 000000 bit name description write read 7:2 gf[5:0] general purpose flags sets the logic value. returns the logic value. 1 stop stop mode select writing 1 places the device in stop mode. n/a 0 idle idle mode select writing 1 places the device in idle mode. n/a www.datasheet.in
c8051f99x-c8051f98x 170 rev. 1.0 16. cyclic redundancy check unit (crc0) c8051f99x-c8051f98x devices include a cyclic redund ancy check unit (crc0) that can perform a crc using a 16-bit polynomial. crc0 accepts a stream of 8-bit data written to the crc0in register. crc0 posts the 16-bit result to an internal register. the intern al result register may be accessed indirectly using the crc0pnt bits and crc0dat register, as shown in figure 16.1 . crc0 also has a bit reverse register for quick data manipulation. figure 16.1. crc0 block diagram 16.1. crc algorithm the c8051f99x-c8051f98x crc unit generates a crc result equivalent to the following algorithm: 1. xor the input with the most-significant bits of the cu rrent crc result. if this is the first iteration of the crc unit, the current crc result will be the set initial value ? (0x00000000 or 0xffffffff). 2a. if the msb of the crc result is set, shift the crc result and xor the re sult with the selected polynomial. 2b. if the msb of the crc result is not set, shift the crc result. ? repeat steps 2a/2b for the number of input bits (8). the algorithm is also described in the following exam - ple. ? crc0in 8 crc0dat crc0cn crc0sel crc0init crc0val crc0pnt0 crc engine 2 to 1 mux result 16 8 8 8 crc0auto crc0cnt automatic crc controller flash memory 8 crc0flip write crc0flip read www.datasheet.in
rev. 1.0 171 c8051f99x-c8051f98x the 16-bit c8051f99x-c8051f98x crc algorithm can be described by the following code: unsigned short updatecrc (unsigned short crc_acc, unsigned char crc_input) { unsigned char i; // loop counter #define poly 0x1021 // create the crc "dividend" for polynomial arithmetic (binary arithmetic // with no carries) crc_acc = crc_acc ^ (crc_input << 8); // "divide" the poly into the dividend using crc xor subtraction // crc_acc holds the "remainder" of each divide // // only complete this division for 8 bits since input is 1 byte for (i = 0; i < 8; i++) { // check if the msb is set (if msb is 1, then the poly can "divide" // into the "dividend") if ((crc_acc & 0x8000) == 0x8000) { // if so, shift the crc value, and xor "subtract" the poly crc_acc = crc_acc << 1; crc_acc ^= poly; } else { // if not, just shift the crc value crc_acc = crc_acc << 1; } } // return the final remainder (crc value) return crc_acc; } ? ta b l e 16.1 lists several input values and the associated outputs using the 16-bit c8051f99x-c8051f98x crc algorithm: table 16.1. example 16-bit crc outputs input output 0x63 0xbd35 0x8c 0xb1f4 0x7d 0x4eca 0xaa, 0xbb, 0xcc 0x6cf6 0x00, 0x00, 0xaa, 0xbb, 0xcc 0xb166 www.datasheet.in
c8051f99x-c8051f98x 172 rev. 1.0 16.2. preparing for a crc calculation to prepare crc0 for a crc calculation, software should set the initial value of the result. the polynomial used for the crc computation is 0x1021. the crc0 result may be initialized to one of two values: 0x0000 or 0xffff. the following steps can be used to initialize crc0. 1. select the initial result value (set crc0val to 0 for 0x00 00 or 1 for 0xffff). 2. set the result to its initia l value (write 1 to crc0init). 16.3. performing a crc calculation once crc0 is initialized, the input data stream is sequenti ally written to crc0in, one byte at a time. the crc0 result is automatically updated after each byte is written. the crc engine may also be configured to automatically perform a crc on one or more 256 byte blocks. the follo wing steps can be used to automat - ically perform a crc on flash memory. 1. prepare crc0 for a crc calculation as shown above. 2. write the index of the starting page to crc0auto. 3. set the autoen bit in crc0auto. 4. write the number of 256 byte blocks to perform in the crc calculation to crc0cnt. 5. write any value to crc0cn (or or its contents with 0x00) to initiate the c rc calculation. the cpu will not execute code any additional code until the crc operation completes. see the note in sfr definition 16.1. crc0cn: crc0 cont rol for more information on how to properly initiate a crc calculation. 6. clear the autoen bit in crc0auto. 7. read the crc result using the procedure below. 16.4. accessing the crc0 result the internal crc0 result is 16 bits. the crc0pnt bits select the byte that is ta rgeted by r ead and write operations on crc0dat and increment after each read or write. the ca lculation result will remain in the internal cr0 result register until it is set, overwritten, or addi tional data is written to crc0in. www.datasheet.in
rev. 1.0 173 c8051f99x-c8051f98x sfr page = all; sfr address = 0x84 sfr definition 16.1. crc0cn: crc0 control bit 7 6 5 4 3 2 1 0 name crc0init crc0val crc0pnt type rrrrr/wr/wrr/w reset 00010000 bit name function 7:4 unused read = 0001b; write = don?t care. 3 crc0init crc0 result init ialization bit. writing a 1 to this bit initializes th e entire crc result based on crc0val. 2 crc0val crc0 set value initialization bit. this bit selects the set value of the crc result. 0: crc result is set to 0x00000000 on write of 1 to crc0init. 1: crc result is set to 0xfff fffff on write of 1 to crc0init. 1 unused read = 0b; write = don?t care. 0 crc0pnt crc0 result pointer. specifies the byte of the crc result to be read/written on the next access to crc0dat. the value of these bits will auto -increment upon ea ch read or write. 0: crc0dat accesses bits 7?0 of the 16-bit crc result. 1: crc0dat accesses bits 15?8 of the 16-bit crc result. note: upon initiation of an automatic crc calculation, the three cycles following a write to crc0cn that initiate a crc operation must only contain instructions which exec ute in the same number of cycles as the number of bytes in the instruction. an example of such an instruction is a 3-byte mov that targets the crc0flip register. when programming in c, the dummy value wr itten to crc0flip should be a non-zero value to prevent the compiler from generating a 2-byte mov instruction. www.datasheet.in
c8051f99x-c8051f98x 174 rev. 1.0 sfr page = all; sfr address = 0x85 sfr page = all; sfr address = 0x86 sfr definition 16.2. crc0in: crc0 data input bit 7 6 5 4 3 2 1 0 name crc0in[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 crc0in[7:0] crc0 data input. each write to crc0in result s in the written data being computed into the existing crc result according to th e crc algorithm described in section 16.1 sfr definition 16.3. crc0dat: crc0 data output bit 7 6 5 4 3 2 1 0 name crc0dat[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 crc0dat[7:0] crc0 data output. each read or write performed on crc0dat targets the crc result bits pointed to by the crc0 result pointer (crc0pnt bits in crc0cn). www.datasheet.in
rev. 1.0 175 c8051f99x-c8051f98x sfr page = all; sfr address = 0x9e sfr definition 16.4. crc0auto: crc0 automatic control bit 7 6 5 4 3 2 1 0 name autoen crcdone crc0st[4:0] type r/w r r/w reset 0 1 0 0 0 0 0 0 bit name function 7 autoen automatic crc calc ulation enable. when autoen is set to 1, any write to crc0cn will initiate an automatic crc starting at flash sector crc0st and continuing for crc0cnt sectors. 6 crcdone crcdone automatic crc calculation complete. set to 0 when a crc calculation is in progress. code execution is stopped during a crc calculation; therefore, read s from firmware will always return 1. 5 unused read = 0b; write = don?t care. 4:0 crc0st[4:0] automatic crc calculat ion starting block. these bits specify the flash block to st art the automatic crc calculation. the starting address of the first flash block included in the automatic crc calculation is crc0st x block size. note: the block size is 256 bytes. www.datasheet.in
c8051f99x-c8051f98x 176 rev. 1.0 sfr page = all; sfr address = 0x9a sfr definition 16.5. crc0cnt: crc0 automati c flash sector count bit 7 6 5 4 3 2 1 0 name crc0cnt[4:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:5 unused read = 00b; write = don?t care. 4:0 crc0cnt[4:0] automatic crc calcul ation block count. these bits specify the number of flash blocks to include in an automatic crc cal - culation. the last address of the last flash block included in the automatic crc calculation is (crc0st+crc0cnt) x block size - 1. ? notes: 1. the block size is 256 bytes. 2. the maximum number of blocks that may be computed in a single operation is 31. to compute a crc on all 32 blocks, perf orm one operation on 31 blocks, then perform a second operation on 1 block without clearing the crc result. www.datasheet.in
rev. 1.0 177 c8051f99x-c8051f98x 16.5. crc0 bit reverse feature crc0 includes hardware to reverse the bit order of each bit in a byte as shown in figure 16.2 . each byte of data written to crc0flip is read back bit reversed. for example, if 0xc0 is written to crc0flip, the data read back is 0x03. bit reversal is a useful mathem atical function used in algorithms such as the fft. figure 16.2. bit reverse register sfr page = all; sfr address = 0x9c sfr definition 16.6. crc0flip: crc0 bit flip bit 7 6 5 4 3 2 1 0 name crc0flip[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 crc0flip[7:0] crc0 bit flip. any byte written to crc0flip is read back in a bit-reversed order, i.e. the written lsb becomes the msb. for example: if 0xc0 is written to crc0flip, the data read back will be 0x03. if 0x05 is written to crc0flip, the data read back will be 0xa0. crc0flip write crc0flip read www.datasheet.in
c8051f99x-c8051f98x 178 rev. 1.0 17. voltage regulator (vreg0) c8051f99x-c8051f98x devices include an internal volt age regulator (vreg0) to regulate the internal core supply to 1.8 v from a vdd supply of 1.8 to 3.6 v. electrical characteristic s for the on-chip regulator are specified in the electric al specifications chapter. the reg0cn register allows the prec ision oscillator bias to be disabled , reducing supply current in all non-sleep power modes. this bias should only be disabl ed when the prec ision oscillator is not being used. the internal regulator (vreg0) is disabled when the device enters sleep mode and remains enabled when the device enters suspend mode. see section ?15. power management? on page 161 for complete details about low power modes. sfr page = 0x0; sfr address = 0xc9 17.1. voltage regulator el ectrical specifications see ta b l e 4.15 on page 62 for detailed voltage regulato r electrical specifications. sfr definition 17.1. reg0cn: voltage regulator control bit 7 6 5 4 3 2 1 0 name reserved reserved oscbias reserved type r r/w r/w r/w r r r r/w reset 00000000 bit name function 7 unused read = 0b. write = don?t care. 6:5 reserved read = 0b. must write 0b. 4 oscbias precision oscillator bias. when set to 1, the bias used by the precis ion oscillator is forced on. if the precision oscillator is not being used, this bit may be cl eared to 0 to reduce supply current in all non-sleep power modes. 3:1 unused read = 000b. write = don?t care. 0 reserved read = 0b. must write 0b. www.datasheet.in
rev. 1.0 179 c8051f99x-c8051f98x 18. reset sources reset circuitry allows the controller to be easily placed in a predefined default condition. on entry to this reset state, th e following occur: ? cip-51 halts program execution ? special function registers (sfrs) are initialized to their defined reset values ? external port pins are forced to a known state ? interrupts and timers are disabled all sfrs are reset to the predefined values noted in the sfr descriptions. the contents of ram are unaffected during a reset; any previously stored data is preserved as long as power is not lost. since the stack pointer sfr is reset, the stack is effectively lo st, even though the data on the stack is not altered. the port i/o latches are reset to 0xff (all logic ones) in open-drain mode. weak pullups are enabled during and after the reset. for v dd monitor and power-on resets, the rst pin is driven low until the device exits the reset state. on exit from the reset state, the program counter (pc) is reset, and the system clock defaults to an internal oscillator. refer to section ?19. clocking sources? on page 186 for information on selecting and configuring the system clock source. the watchdog time r is enabled with the system clock divided by 12 as its clock source ( section ?26.4. watchdog timer mode? on page 309 details the use of the watchdog timer). program execution begins at location 0x0000. figure 18.1. reset sources pca wdt missing clock detector (one- shot) (software reset) system reset reset funnel px.x px.x en swrsf system clock cip-51 microcontroller core extended interrupt handler en wdt enable mcd enable illegal flash operation rst (wired-or) '0' + - comparator 0 vdd + - supply monitor enable smartclock rtc0re c0rsef power-on reset power management block (pmu0) system reset vdd power on reset reset www.datasheet.in
c8051f99x-c8051f98x 180 rev. 1.0 18.1. power-on reset during power-up, the device is held in a reset state and the rst pin voltage tracks v dd (through a weak pull-up) until the device is released from reset. after vdd settles abov e vpor, a delay occurs before the device is released from reset; the delay decreases as the v dd ramp time increases (v dd ramp time is defined as how fast v dd ramps from 0 v to v por ). figure 18.2 plots the power-on and v dd monitor reset timing. for valid ramp times (less than 3 ms), the power-on reset delay (t pordelay ) is typically 7 ms (v dd = 1.8 v) or 15 ms (v dd = 3.6 v). note: the maximum v dd ramp time is 3 ms; slower ramp times may cause the device to be released from reset before v dd reaches the v por level. on exit from a power-on reset, the porsf fl ag (rstsrc.1) is set by hardware to logic 1. when porsf is set, all of the other reset flags in the rstsrc regist er are indeterminate (porsf is cleared by all other resets). since all resets cause program execution to begin at the same location (0x0000), software can read the porsf flag to determine if a power-up was the cause of reset. the contents of internal data memory should be assumed to be undefined after a power-on reset. the por supply monitor can be disabled to save power by writing 1 to the mondis (pmu0md.5) bit. when the por supply monitor is di sabled, all reset sources will trigge r a full por and will re-enable the por supply monitor. figure 18.2. power-fail reset timing diagram 18.2. power-fail reset c8051f99x-c8051f98x devices have a v dd supply monitor that is enabled and selected as a reset source after each power-on or power-fail reset. when enabled and selected as a reset source, any power down transition or power irregularity that causes v dd to drop below v rst will cause the rst pin to be driven low and the cip-51 will be held in a reset state (see figure 18.2 ). when v dd returns to a level above v rst , the cip-51 will be released from the re set state. after a power-fail reset, the porsf flag reads 1, the contents of ram invalid, and the v dd supply monitor power-on reset power-on reset rst t volts logic high logic low t pordelay v d d v por vdd see specification table for min/max voltages. t pordelay www.datasheet.in
rev. 1.0 181 c8051f99x-c8051f98x is enabled and selected as a reset source. the enable state of the v dd supply monitor and its selection as a reset source is only altered by power-on and power-fail resets. for example, if the v dd supply monitor is de-selected as a reset source and disabled by software, then a software reset is performed, the v dd supply monitor will remain disabled and de-selected after the reset. in battery-operated systems, the contents of ram c an be preserved near the end of the battery?s usable life if the device is placed in sleep mode prior to a power-fail reset occurring. when the device is in sleep mode, the power-fail reset is automatically disabled and the contents of ram ar e preserved as long as v dd does not fall below v por . a large capacitor can be used to hold the power supply voltage above v por while the user is replacing the battery. upon waking from sleep mode, the enable and reset source select state of the v dd supply monitor are restored to the value last set by the user. to allow software early notification that a power failure is about to occur, the vddok bit is cleared when the v dd supply falls below the v warn threshold. the vddok bit can be configured to generate an interrupt. see section ?13. interrupt handler? on page 137 for more details. important note: to protect the integrity of flash contents, the v dd supply monitor must be enabled and selected as a reset source if software contains routines which erase or write flash memory. if the v dd supply monitor is not enabled, any erase or write performed on flash memory will cause a flash error device reset. important notes: ? the power-on reset (por) delay is not incurred after a v dd supply monitor reset. see section ?4. electrical characteristics? on page 46 for complete electrical characteristics of the v dd monitor. ? software should take care not to inadvertently disable the v dd monitor as a reset source when writing to rstsrc to enable other reset sources or to trigge r a software reset. all writes to rstsrc should explicitly set porsf to 1 to keep the v dd monitor enabled as a reset source. ? the v dd supply monitor must be enabled bef ore selecting it as a reset source . selecting the v dd supply monitor as a reset source before it has stabilized may ge nerate a system re set. in systems where this reset would be undesirable, a delay should be introduced between enabling the v dd supply monitor and selecting it as a reset source. see section ?4. electrical characteristics? on page 46 for minimum v dd supply monitor turn-on time. no delay should be introduced in systems where software contains routines that erase or write flash memory. the procedure for enabling the v dd supply monitor and selecting it as a reset source is shown below: 1. enable the v dd supply monitor (vdmen bit in vdm0cn = 1). 2. wait for the v dd supply monitor to stabilize (optional). 3. select the v dd supply monitor as a reset source (porsf bit in rstsrc = 1). www.datasheet.in
c8051f99x-c8051f98x 182 rev. 1.0 sfr page = 0x0; sfr address = 0xff 18.3. external reset the external rst pin provides a means for external circuitr y to force the device into a reset state. asserting an active-low signal on the rst pin generates a reset; an exte rnal pullup and/or decoupling of the rst pin may be necessary to avoid erroneous noise-induced resets. see ta b l e 4.4 for complete rst pin specifications. the external rese t remains functional even when the device is in the low power suspend and sleep modes. the pinrsf flag (rstsrc.0) is set on exit from an external reset. 18.4. missing clock detector reset the missing clock detector (mcd) is a one-shot circuit that is triggered by the system clock. if the system clock remains high or low for more than 100 s, the one-shot will time out an d generate a reset. after a mcd reset, the mcdrsf flag (rstsrc.2) will read 1, signifying the mcd as the reset source; otherwise, sfr definition 18.1. vdm0cn: vdd supply monitor control bit 7 6 5 4 3 2 1 0 name vdmen vddstat vddok vddokie type r/w r r r r/w r r r reset 1 varies varies 0 1 0 0 0 bit name function 7 vdmen v dd supply monitor enable. this bit turns the v dd supply monitor circuit on/off. the vdd supply monitor cannot generate system resets until it is also se lected as a reset source in register rst - src ( sfr definition 18.2 ). 0: v dd supply monitor disabled. 1: v dd supply monitor enabled. 6 vddstat v dd supply status. this bit indicates the current power supply status. 0: v dd is at or below the v rst threshold. 1: v dd is above the v rst threshold. 5 vddok v dd supply status (early warning). this bit indicates the current v dd power supply status. 0: v dd is at or below the vdd warn threshold. 1: v dd is above the vdd warn threshold. 4 unused read = 0b. write = don?t care. 3 vddokie v dd early warning interrupt enable. enables the v dd early warning interrupt. 0: v dd early warning interrupt is disabled. 1: v dd early warning interrupt is enabled. 2:0 unused read = 000b. write = don?t care. www.datasheet.in
rev. 1.0 183 c8051f99x-c8051f98x this bit reads 0. writing a 1 to the mcdrsf bit enables the missing clock detector; writing a 0 disables it. the missing clock detector reset is automatically disabl ed when the device is in the low power suspend or sleep mode. upon exit from either low power state, the enabled/disabled state of this reset source is restored to its previous value. the state of the rst pin is unaffected by this reset. 18.5. comparator0 reset comparator0 can be configured as a reset source by writing a 1 to the c0rsef flag (rstsrc.5). comparator0 should be enabled and allowed to settle prior to writing to c0rsef to prevent any turn-on chatter on the output from generating an unwanted rese t. the comparator0 reset is active-low: if the non- inverting input voltage (on cp0+) is less than the inverting input voltage (on cp0?), the device is put into the reset state. after a compar ator0 reset, the c0rsef flag (rst src.5) will read 1 signifying comparator0 as the reset source; otherwise, this bit reads 0. the comparator0 reset source remains functional even when the device is in the low power suspend and sleep states as long as comparator0 is also enabled as a wake-up source. the state of the rst pin is unaffected by this reset. 18.6. pca watchdog timer reset the programmable watchdog timer (wdt) function of the programmable counter array (pca) can be used to prevent software from running out of control during a system malfunction. the pca wdt function can be enabled or disabled by software as described in section ?26.4. watchdog timer mode? on page 309 ; the wdt is enabled and clocked by sysclk / 12 following any reset. if a system malfunction prevents user software from updating the wdt, a reset is ge nerated and the wdtrsf bit (rstsrc.5) is set to 1. the pca watchdog timer reset source is automatically disabled when the device is in the low power suspend or sleep mode. upon exit from either low power state, the enabled/disabled state of this reset source is restored to its previous value.the state of the rst pin is unaffected by this reset. 18.7. flash error reset if a flash read/write/era se or program read targets an illegal address, a system reset is generated. this may occur due to any of the following: ? a flash write or erase is attempted above user code space. this occurs when pswe is set to 1 and a movx write operation targets an address above the lock byte address. ? a flash read is attempted above user code space. this occurs when a movc operation targets an address above the lock byte address. ? a program read is attempted above user code space. this occurs when user code attempts to branch to an address above the lock byte address. ? a flash read, write or erase attempt is restrict ed due to a flash security setting (see section ?14.3. security options? on page 151). ? a flash write or erase is attempted while the v dd monitor is disabled. the ferror bit (rstsrc.6) is set following a flash error reset. the state of the rst pin is unaffected by this reset. 18.8. smartclock (real time clock) reset the smartclock can generate a system reset on two events: smartclock oscillator fail or smartclock alarm. the smartclock oscillator fa il event occurs when the smartclock missing clock detector is enabled and the smartclo ck clock is below approximately 20 khz. a smartclock alarm event occurs when the smartclock alarm is enab led and the smartclock timer value matches the alarmn registers. the smartclock can be configured as a reset source by writing a 1 to the rtc0re flag (rstsrc.7). the smartclock reset remains functional even when the device is in the low power suspend or sleep mode. the state of the rst pin is unaffected by this reset. www.datasheet.in
c8051f99x-c8051f98x 184 rev. 1.0 18.9. software reset software may force a reset by wr iting a 1 to the swrsf bit (rst src.4). the swrsf bit will read 1 following a software forced reset. the state of the rst pin is unaffected by this reset. www.datasheet.in
rev. 1.0 185 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xef. sfr definition 18.2. rstsrc: reset source bit 7 6 5 4 3 2 1 0 name rtc0re ferror c0rsef swrsf wdtrsf mcdrsf porsf pinrsf type r/w r r/w r/w r r/w r/w r reset varies varies varies varies varies varies varies varies bit name description write read 7 rtc0re smartclock reset enable and flag 0: disable smartclock as a reset source. 1: enable smartclock as a reset source. set to 1 if smartclock alarm or oscillator fail caused the last reset. 6 ferror flash error reset flag. n/a set to 1 if flash read/write/erase error caused the last reset. 5 c0rsef comparator0 reset enable and flag. 0: disable comparator0 as a reset source. 1: enable comparator0 as a reset source. set to 1 if comparator0 caused the last reset. 4 swrsf software reset force and flag. writing a 1 forces a sys - tem reset. set to 1 if last reset was caused by a write to swrsf. 3 wdtrsf watchdog timer reset flag. n/a set to 1 if watchdog timer overflow caused the last reset. 2 mcdrsf missing clock detector (mcd) enable and flag. 0: disable the mcd. 1: enable the mcd. the mcd triggers a reset if a missing clock condition is detected. set to 1 if missing clock detector timeout caused the last reset. 1 porsf power-on / power-fail reset flag, and power-fail reset enable. 0: disable the vdd supply monitor as a reset source. 1: enable the vdd supply monitor as a reset source. 3 set to 1 anytime a power- on or v dd monitor reset occurs. 2 0 pinrsf hw pin reset flag. n/a set to 1 if rst pin caused the last reset. notes: 1. it is safe to use read-modify-write operations (orl, anl, etc.) to enable or disable specific interrupt sources. 2. if porsf read back 1, the value read from all other bits in this register are indeterminate. 3. writing a 1 to porsf before the vdd supply mo nitor is stabilized may generate a system reset. www.datasheet.in
c8051f99x-c8051f98x 186 rev. 1.0 19. clocking sources c8051f99x-c8051f98x devices include a programmable prec ision internal oscillator, an external oscillator drive circuit, a low power internal oscillator, and a smartclock real ti me clock oscillator. the precision internal oscillator can be enabled/disabled and calibrated using the oscicn and oscicl registers, as shown in figure 19.1 . the external oscillator can be config ured using the oscxcn register. the low power internal oscillator is automatically enabled and disabled when selected and dese lected as a clock source. smartclock operation is described in the smartclock oscillator chapter. the system clock (sysclk) can be der ived from the precision internal oscill ator, external oscillator, low power internal oscillator, low power internal oscillato r divided by 8, or smartc lock oscillator. the global clock divider can generate a system clock that is 1, 2, 4, 8, 16, 32, 64, or 128 times slower that the selected input clock source. oscillator electric al specifications can be found in the electrical specifications chapter. figure 19.1. clocking sources block diagram the proper way of changing the system clock when bo th the clock source and the clock divide value are being changed is as follows: if switching from a fast ?undivided? clock to a slower ?undivided? clock: 1. change the clock divide value. 2. poll for clkrdy > 1. 3. change the clock source. if switching from a slow ?undivided? clock to a faster ?undivided? clock: 1. change the clock source. 2. change the clock divide value. 3. poll for clkrdy > 1. external oscillator drive circuit xtal1 xtal2 option 2 vdd xtal2 option 1 10m ? option 4 xtal2 oscxcn xtlvld xoscmd2 xoscmd1 xoscmd0 xfcn2 xfcn1 xfcn0 precision internal oscillator en oscicl oscicn ioscen ifrdy sysclk clksel clkdiv2 clkdiv1 clkdiv0 clkrdy clksl1 clksl0 smartclock oscillator clock divider n low power internal oscillator low power internal oscillator smartclock oscillator external oscillator precision internal oscillator clkrdy option 3 xtal2 8 low power internal oscillator divided by 8 www.datasheet.in
rev. 1.0 187 c8051f99x-c8051f98x 19.1. programmable precisi on internal oscillator all c8051f99x-c8051f98x devices include a programma ble precision internal oscillator that may be selected as the system clock. oscicl is factory calibrate d to obtain a 24.5 mhz frequency. see section ?4. electrical characteristics? on page 46 for complete oscilla tor specifications. the precision oscillator supports a spread spectrum mode which modulates the out put frequency in order to reduce the emi generated by t he system. when enabled (sse = 1), the oscillato r output frequency is modulated by a stepped triangle wave whose frequenc y is equal to the oscillato r frequency divided by 384 (63.8 khz using the factory calibration). the deviation from the nominal oscillator frequen cy is +0%, ?1.6%, and the step size is typically 0.26% of the nominal fr equency. when using this mode, the typical average oscillator frequency is lowered from 24.5 mhz to 24.3 mhz. 19.2. low power internal oscillator all c8051f99x-c8051f98x devices in clude a low power internal oscilla tor that defaults as the system clock after a system reset. the low power internal oscillator frequency is 20 mhz 10% and is automati - cally enabled when selected as the system clock and disabled when not in use. see section ?4. electrical characteristics? on page 46 for complete oscillator specifications. 19.3. external oscill ator drive circuit all c8051f99x-c8051f98x devices include an external osc illator circuit that may dr ive an external crystal, ceramic resonator, capacitor, or rc network. a cmos clock ma y also provide a clock input. figure 19.1 shows a block diagram of the four external oscillator options. the extern al oscillator is enabled and config - ured using the oscxcn register. the external oscillato r output may be selected as the system clock or used to clock some of the digital peripherals (e.g., timers, pca, etc.). see the data sheet chapters for each digital peripheral for details. see section ?4. electrical characteristics? on page 46 for complete oscilla tor specifications. 19.3.1. external crystal mode if a crystal or ceramic resonator is used as the external oscillator, the crystal/resonator and a 10 m ?? resis - tor must be wired across the xtal1 and xtal2 pins as shown in figure 19.1 , option 1. appropriate load - ing capacitors should be added to xtal1 and xtal2, and both pins should be configured for analog i/o with the digital output drivers disabled. figure 19.2 shows the external oscillator circuit for a 20 mhz quartz crystal with a manufacturer recom - mended load capacitance of 12.5 pf. loading capacitors are "in series" as seen by the crystal and "in par - allel" with the stray capacitance of the xtal1 and xtal2 pins. the total value of the each loading capacitor and the stray capacitance of each xtal pin should equal 12.5 pf x 2 = 25 pf. with a stray capacitance of 10 pf per pin, the 15 pf capacitors yield an equivale nt series capacitance of 12.5 pf across the crystal. note: the recommended load capacitance depends upon the crystal and the manufacturer. please refer to the crystal data sheet when completing these calculations. www.datasheet.in
c8051f99x-c8051f98x 188 rev. 1.0 figure 19.2. 25 mhz external crystal example important note on external crystals: crystal oscillator circuits are qui te sensitive to pcb layout. the crystal should be placed as close as possible to the xtal pins on the device. the traces should be as short as possible and shielded with ground plane fr om any other traces which could introduce noise or interference. when using an external crystal, the external oscillator drive circuit must be configured by software for crys - tal oscillator mode or crystal oscillator mode with divide by 2 stage . the divide by 2 stage ensures that the clock derived from the external o scillator has a duty cycle of 50%. t he external oscillator frequency con - trol value (xfcn) must also be specified based on th e crystal frequency. the selection should be based on ta b l e 19.1 . for example, a 25 mhz crystal requires an xfcn setting of 111b. when the crystal oscillator is first enabled, the external osc illator valid detector allo ws software to deter - mine when the external system clock has stabilized. s witching to the external oscillator before the crystal oscillator has stabilized can result in unpredictable behavior . the recommended procedu re for starting the crystal is as follows: 1. configure xtal1 and xtal2 for analog i/o and disable the digital output drivers. 2. configure and enable the external oscillator. 3. poll for xtlvld => 1. 4. switch the system clock to the external oscillator. table 19.1. recommended xfcn settings for crystal mode xfcn crystal frequency bias current typical supply current (vdd = 2.4 v) 000 f ? 20 khz 0.5 a 3.0 a, f = 32.768 khz 001 20 khz ?? f ?? 58 khz 1.5 a 4.8 a, f = 32.768 khz 010 58 khz ? f ?? 155 khz 4.8 a 9.6 a, f = 32.768 khz 011 155 khz ? f ?? 415 khz 14 a 28 a, f = 400 khz 100 415 khz ? f ?? 1.1 mhz 40 a 71 a, f = 400 khz 101 1.1 mhz ? f ?? 3.1 mhz 120 a 193 a, f = 400 khz 110 3.1 mhz ? f ?? 8.2 mhz 550 a 940 a, f = 8 mhz 111 8.2 mhz ? f ?? 25 mhz 2.6 ma 3.9 ma, f = 25 mhz 15 pf 15 pf 25 mhz xtal1 xtal2 10 mohm www.datasheet.in
rev. 1.0 189 c8051f99x-c8051f98x 19.3.2. external rc mode if an rc network is used as the external oscillator, the circuit should be configured as shown in figure 19.1 , option 2. the rc network should be added to xtal2, and xtal2 should be configured for analog i/o with the digital output drivers disabled. xtal1 is not affected in rc mode. the capacitor should be no greater than 100 pf; however for very small capacitors, the total capacitance may be dominated by parasitic capacitance in the pcb layout. the resistor should be no smaller than 10 k ? . the oscillation frequency can be de termined by the following equation: where ? f = frequency of clock in mhzr = pull-up resistor value in k ? ? v dd = power supply voltage in voltsc = capacitor value on the xtal2 pin in pf to determine the required external oscillator frequency control va lue (xfcn) in the oscxcn register, first select the rc network value to produce the desired frequ ency of oscillation. for example, if the fre - quency desired is 100 khz, let r = 246 k ? and c = 50 pf: where ? f = frequency of clock in mhz r = pull-up resistor value in k ? ? v dd = power supply voltage in volts c = capacitor value on the xtal2 pin in pf referencing table 19.2 , the recommended xfcn setting is 010. when the rc oscillator is first enabled , the external oscillator valid detect or allows software to determine when oscillation has stabilized. the recommended procedure fo r starting the rc oscillator is as follows: 1. configure xtal2 for analog i/o and disable the digital output drivers. 2. configure and enable the external oscillator. 3. poll for xtlvld > 1. 4. switch the system clock to the external oscillator. table 19.2. recommended xfcn settings for rc and c modes xfcn approximate frequency range (rc and c mode) k factor (c mode) typical supply current/ actual measured frequency (c mode, vdd = 2.4 v) 000 f ?? 25 khz k factor = 0.87 3.0 a, f = 11 khz, c = 33 pf 001 25 khz ?? f ?? 50 khz k factor = 2.6 5.5 a, f = 33 khz, c = 33 pf 010 50 khz ?? f ?? 100 khz k factor = 7.7 13 a, f = 98 khz, c = 33 pf 011 100 khz ?? f ?? 200 khz k factor = 22 32 a, f = 270 khz, c = 33 pf 100 200 khz ?? f ?? 400 khz k factor = 65 82 a, f = 310 khz, c = 46 pf 101 400 khz ?? f ?? 800 khz k factor = 180 242 a, f = 890 khz, c = 46 pf 110 800 khz ?? f ?? 1.6 mhz k factor = 664 1.0 ma, f = 2.0 mhz, c = 46 pf 111 1.6 mhz ?? f ?? 3.2 mhz k factor = 1590 4.6 ma, f = 6.8 mhz, c = 46 pf f 1.23 10 3 ? rc ? ------------------------ - = f 1.23 10 3 ? rc ? ------------------------ - 1.23 10 3 ? 246 50 ? ------------------------ - 100 khz === www.datasheet.in
c8051f99x-c8051f98x 190 rev. 1.0 19.3.3. external capacitor mode if a capacitor is used as the external oscillator, the circuit should be configured as shown in figure 19.1 , option 3. the capacitor should be added to xtal2, a nd xtal2 should be configured for analog i/o with the digital output drivers disabled. xtal1 is not affected in rc mode. the capacitor should be no greater than 100 pf; however, for very small ca pacitors, the total capacitance may be dominated by parasitic capacitance in the pcb layout. the oscillation fr equency and th e required external oscillator frequency control value (xfcn) in the os cxcn register can be determined by the following equation: where ? f = frequency of clock in mhzr = pull-up resistor value in k ? ? v dd = power supply voltage in voltsc = capacitor value on the xtal2 pin in pf below is an example of selecting the capacitor an d finding the frequency of oscillation assume v dd = 3.0 v and f = 150 khz: since a frequency of roughly 150 khz is desired, select the k factor from ta b l e 19.2 as kf = 22: therefore, the xfcn value to use in this example is 011 and c is approximately 50 pf. the recommended startup procedure for c mode is the same as rc mode. 19.3.4. external cmos clock mode if an external cmos clock is used as the external oscillator, the clock shou ld be directly routed into xtal2. the xtal2 pin should be configured as a digital input. xtal1 is not used in external cmos clock mode. the external oscillator valid detector will always return zero when the external oscilla tor is configured to external cmos clock mode. f kf cv dd ? --------------------- = f kf cv dd ? --------------------- = 0.150 mhz kf c3.0 ? ----------------- = 0.150 mhz 22 c 3.0 v ? ----------------------- = c 22 0.150 mhz 3.0 v ? ---------------------------------------------- - = c 48.8 pf = www.datasheet.in
rev. 1.0 191 c8051f99x-c8051f98x 19.4. special function register s for selecting and confi guring the system clock the clocking sources on c8051f99x-c8051f98x device s are enabled and configured using the oscicn, oscicl, oscxcn and the smartclo ck internal registers. see section ?20. smartclock (real time clock)? on page 195 for smartclock register descriptions. th e system clock source for the mcu can be selected using the clksel register. to minimize active mode current, the oneshot timer which sets flash read time should by bypassed when the system clock is greater than 10 mhz. see the flscl register description for details. the clock selected as the system cloc k can be divided by 1, 2, 4, 8, 16 , 32, 64, or 128. when switching between two clock divide values, the transition may ta ke up to 128 cycles of th e undivided clock source. the clkrdy flag can be polled to determine when the new clock divide value has been applied. the clock divider must be set to "divide by 1" when entering suspend or sleep mode. the system clock source may also be switched on-the -fly. the switchover takes effect after one clock period of the sl ower oscillator. sfr page = all; sfr address = 0xa9 sfr definition 19.1. clksel: clock select bit 7 6 5 4 3 2 1 0 name clkrdy clkdiv[2:0] clksel[2:0] type r r/w r/w r/w reset 00010010 bit name function 7 clkrdy system clock divider clock ready flag. 0: the selected clock divide setting has not been applied to the system clock. 1: the selected clock divide setting has been applied to the system clock. 6:4 clkdiv[2:0] system clock divider bits. selects the clock division to be applie d to the undivided system clock source. 000: system clock is divided by 1. 001: system clock is divided by 2. 010: system clock is divided by 4. 011: system clock is divided by 8. 100: system clock is divided by 16. 101: system clock is divided by 32. 110: system clock is divided by 64. 111: system clock is divided by 128. 3 unused read = 0b. must write 0b. 2:0 clksel[2:0] system clock select. selects the oscillator to be used as the undivided system clock source. 000: precision internal oscillator. 001: external oscillator. 010: low power osc illator divided by 8. 011: smartclock oscillator. 100: low power oscillator. all other values reserved. www.datasheet.in
c8051f99x-c8051f98x 192 rev. 1.0 sfr page = 0x0; sfr address = 0xb2 sfr definition 19.2. oscicn: internal os cillator control bit 7 6 5 4 3 2 1 0 name ioscen ifrdy reserved [5:0] type r/w r r/w r/w r/w r/w r/w r/w reset 0 0 varies varies varies varies varies varies bit name function 7 ioscen internal oscill ator enable. 0: internal osc illator disabled. 1: internal oscillator enabled. 6 ifrdy internal oscillator frequency ready flag. 0: internal oscillator is not r unning at its programmed frequency. 1: internal oscillator is runn ing at its programmed frequency. 5:0 reserved must perform read-modify-write. notes: 1. read-modify-write operations such as orl and anl must be used to set or clear the enable bit of this register. 2. oscbias (reg0cn.4) must be set to 1 before enabling the precision internal oscillator. www.datasheet.in
rev. 1.0 193 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xb3 sfr definition 19.3. oscicl: internal oscillator calibration bit 7 6 5 4 3 2 1 0 name sse oscicl [6:0] type r/w r r/w r/w r/w r/w r/w r/w reset 0 varies varies varies var ies varies varies varies bit name function 7 sse spread spectrum enable. 0: spread spectrum clock dithering disabled. 1: spread spectrum clock dithering enabled. 6:0 oscicl internal oscillator calibration. factory calibrated to obtain a frequency of 24.5 mhz. incrementing this register decreases the oscillator frequency and de crementing this regi ster increases the oscillator frequency. the step size is approximately 1% of the calibra ted frequency. the recommended calibration frequency range is between 16 and 24.5 mhz. note: if the precision internal oscillator is selected as the system clock, th e following procedure should be used when changing the value of the internal oscillator calibration bits. ? 1. switch to a different clock source. ? 2. disable the oscillator by writing oscicn.7 to 0. ? 3. change oscicl to the desired setting. ? 4. enable the oscillator by writing oscicn.7 to 1. www.datasheet.in
c8051f99x-c8051f98x 194 rev. 1.0 sfr page = 0x0; sfr address = 0xb1 sfr definition 19.4. oscxcn: external oscillator control bit 7 6 5 4 3 2 1 0 name xclkvld xoscmd[2:0] reserved xfcn[2:0] type r r r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7 xclkvld external oscilla tor valid flag. provides external oscillator status and is va lid at all times for a ll modes of operation except external cmos clock mode and external cmos clock mode with divide by 2. in these modes, xclkvld always returns 0. 0: external oscillator is unused or not yet stable. 1: external oscillator is running and stable. 6:4 xoscmd external oscillator mode bits. configures the external oscillato r circuit to the selected mode. 00x: external oscillat or circuit disabled. 010: external cmos clock mode. 011: external cmos clock mode with divide by 2 stage. 100: rc oscillator mode. 101: capacitor oscillator mode. 110: crystal oscillator mode. 111: crystal oscillator mode with divide by 2 stage. 3 reserved read = 0b. must write 0b. 2:0 xfcn external oscillator frequency control bits. controls the external oscillator bias current. 000-111: see ta b l e 19.1 on page 188 (crystal mode) or ta b l e 19.2 on page 189 (rc or c mode) for recommended settings. www.datasheet.in
rev. 1.0 195 c8051f99x-c8051f98x 20. smartclock (real time clock) c8051f99x-c8051f98x devices include an ultra lo w power 32-bit smartclock peripheral (real time clock) with alarm. the smartclock has a dedicated 32 khz oscillator that can be configured for use with or without a crystal. no external resistor or loading capacitors are required. the on-chip loading capacitors are programmable to 16 discrete levels allowing compatibility with a wide range of crystals. the smart - clock can operate directly from a 1.8?3.6 v battery voltage and remains operational even when the device goes into its lowest power down mode. the smartclock output can be buffered and routed to a gpio pin to provide an accurate, low frequency clock to other devices while the mcu is in its lowest power down mode ( see ?pmu0md: power management unit mode? on page 168 for more details). c8051f99x- c8051f98x devices also support an ultra low power internal lfo that reduces sleep mode current. the smartclock allows a maximum of 36 hour 32-bit independent time-keeping when used with a 32.768 khz watch crystal. the smartclock provides an alarm and missing smartclock events, which could be used as reset or wakeup sources. see section ?18. reset sources? on page 179 and section ?15. power management? on page 161 for details on reset sources and low power mode wake-up sources, respectively. figure 20.1. smartclock block diagram smartclock oscillator smartclock cip-51 cpu xtal4 xtal3 rtc0cn capturen rtc0xcf rtc0xcn alarmn rtc0key rtc0adr rtc0dat interface registers internal registers smartclock state machine wake-up 32-bit smartclock timer programmable load capacitors power/ clock mgmt interrupt rtcout lfo www.datasheet.in
c8051f99x-c8051f98x 196 rev. 1.0 20.1. smartclock interface the smartclock interface consists of three regist ers: rtc0key, rtc0adr, and rtc0dat. these inter - face registers are located on the cip-51?s sfr map and provide access to the smartclock internal regis - ters listed in ta b l e 20.1 . the smartclock internal registers can on ly be accessed indirectly through the smartclock interface. 20.1.1. smartclock lock and key functions the smartclock interface has an rt c0key register for legacy reasons, however, a ll writes to this regis - ter are ignored. the smartclock interfac e is always unlocked on c8051f99x-c8051f98x. table 20.1. smartclock internal registers smartclock address smartclock register register name description 0x00?0x03 capturen smartclock capture registers four registers used for setting the 32-bit smartclock timer or reading its current value. 0x04 rtc0cn smartclock control register controls the operation of the smartclock state machine. 0x05 rtc0xcn smartclock oscillator control register controls the operation of the smartclock oscillator. 0x06 rtc0xcf smartclock oscillator configuration register controls the value of the progammable oscillator load capacitance and enables/disables autostep. 0x08?0x0b alarmn smartclock alarm registers four registers used for setting or reading the 32-bit smartclock alarm value. www.datasheet.in
rev. 1.0 197 c8051f99x-c8051f98x 20.1.2. using rtc0adr and rtc0dat to access smartclock internal registers the smartclock internal registers can be read and written using rtc0adr and rtc0dat. the rtc0adr register selects the smartclo ck internal register th at will be targeted by subsequent reads or writes. recommended instruction timing is provided in this section. if the recommended instruction timing is not followed, then busy (rtc0adr.7) should be checked prior to each read or write operation to make sure the smartclock interface is not busy performi ng the previous read or write operation. a smart - clock write operation is initiated by writing to the rtc0dat register. belo w is an example of writing to a smartclock internal register. 1. poll busy (rtc0adr.7) until it returns 0 or follow recommended instruction timing. 2. write 0x05 to rtc0adr. this selects the intern al rtc0cn register at smartclock address 0x05. 3. write 0x00 to rtc0dat. this operation writes 0x00 to the internal rtc0cn register. a smartclock read operation is initiated by setting the smartclock interface busy bit. this transfers the contents of the in ternal register selected by rtc0adr to rtc0dat. the tr ansferred data will remain in rtc0dat until the next read or write operation. below is an example of reading a smartclock internal register. 1. poll busy (rtc0adr.7) until it returns 0 or follow recommended instruction timing. 2. write 0x05 to rtc0adr. this selects the intern al rtc0cn register at smartclock address 0x05. 3. write 1 to busy. this initiates the tr ansfer of data from rtc0cn to rtc0dat. 4. poll busy (rtc0adr.7) until it returns 0 or follow reco mmend instruction timing. 5. read data from rtc0dat. this data is a copy of the rtc0cn register. ? note: the rtc0adr and rtc0dat registers will retain their state upon a device reset. 20.1.3. rtc0adr short strobe feature reads and writes to indirect smart clock registers normally take 7 system clock cycles. to minimize the indirect register access time, the short strobe feat ure decreases the read and write access time to 6 sys - tem clocks. the short strobe feature is automatically enabled on reset and can be manually enabled/dis - abled using the short (rtc0adr.4) control bit. recommended instruction timing for a single register read with short strobe enabled: mov rtc0adr, #095h nop nop nop mov a, rtc0dat ? recommended instruction timing for a single register write with short strobe enabled: mov rtc0adr, #095h mov rtc0dat, #000h nop 20.1.4. smartclock interface autoread feature when autoread is enabled, each read from rtc0dat initiates the next indirect read operation on the smartclock internal register selected by rtc0adr. software should set the busy bit once at the begin - ning of each series of consecutiv e reads. software should follow recommended instruction timing or check if the smartclock interface is busy prior to readin g rtc0dat. autoread is enabled by setting autord (rtc0adr.6) to logic 1. www.datasheet.in
c8051f99x-c8051f98x 198 rev. 1.0 20.1.5. rtc0adr autoincrement feature for ease of reading and writing the 32-bit capture and alarm values, rtc0adr automatically incre - ments after each read or write to a capturen or al armn register. this speeds up the process of setting an alarm or reading the current smartclock timer value. autoincrement is always enabled. recommended instruction timing for a multi-byte regist er read with short strobe and auto read enabled: mov rtc0adr, #0d0h nop nop nop mov a, rtc0dat nop nop mov a, rtc0dat nop nop mov a, rtc0dat nop nop mov a, rtc0dat recommended instruction timing for a multi-by te register write with short strobe enabled: mov rtc0adr, #010h mov rtc0dat, #05h nop mov rtc0dat, #06h nop mov rtc0dat, #07h nop mov rtc0dat, #08h nop www.datasheet.in
rev. 1.0 199 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xae sfr definition 20.1. rtc0key: smartclock lock and key bit 7 6 5 4 3 2 1 0 name rtc0st[7:0] type r/w reset 00000000 bit name function 7:0 rtc0st smartclock interface status. provides lock status when read. read: 0x02: smartclock interface is unlocked. write: writes to rtc0key have no effect. www.datasheet.in
c8051f99x-c8051f98x 200 rev. 1.0 sfr page = 0x0; sfr address = 0xac sfr page= 0x0; sfr address = 0xad sfr definition 20.2. rtc0adr: smartclock address bit 7 6 5 4 3 2 1 0 name busy autord short addr[3:0] type r/w r/w r r/w r/w reset 00000000 bit name function 7 busy smartclock interface busy indicator. indicates smartclock interface status. writin g 1 to this bit initiates an indirect read. 6 autord smartclock interface autoread enable. enables/disables autoread. 0: autoread disabled. 1: autoread enabled. 5 unused read = 0b; write = don?t care. 4 short short strobe enable. enables/disables the short strobe feature. 0: short strobe disabled. 1: short strobe enabled. 3:0 addr[3:0] smartclock indirect register address. sets the currently selected smartclock register. see ta b l e 20.1 for a listing of all smartclock indirect registers. note: the addr bits increment after each indirect read/write operation that targets a capturen or alarmn internal smartclock register. sfr definition 20.3. rtc0dat: smartclock data bit 7 6 5 4 3 2 1 0 name rtc0dat[7:0] type r/w reset 00000000 bit name function 7:0 rtc0dat smartclock data bits. holds data transferred to/from the internal smartclock register selected by rtc0adr. note: read-modify-write instructions (orl, anl, etc.) should not be used on this register. www.datasheet.in
rev. 1.0 201 c8051f99x-c8051f98x 20.2. smartclock clocking sources the smartclock peripheral is clocked from its ow n timebase, independent of the system clock. the smartclock timebase can be derived from an external cmos clock, the internal lfo, or the smart - clock oscillator circuit, wh ich has two modes of operation: crystal mode, and self-oscillate mode. the oscillation frequency is 32.768 khz in crystal mode and can be programmed in the range of 10 khz to 40 khz in self-oscillate mode. the internal lfo fr equency is 16.4 khz 20%. the frequency of the smartclock oscillator can be measured with respect to another oscillator usin g an on-chip timer. see section ?25. timers? on page 276 for more information on how this can be accomplished. note: the smartclock timebase can be selected as the system clock and routed to a port pin. see section ?19. clocking sources? on page 186 for information on selecting the system clock source and section ?21. port input/output? on page 213 for information on how to route the system clock to a port pin. the smartclock timebase can also be routed to a port pin while the device is in its ultra low power sleep mode. see the pmu0md register description for details. 20.2.1. using the smartclock oscillator with a crystal or external cmos clock when using crystal mode, a 32.768 khz crystal should be connected between xtal3 and xtal4. no other external components are required. the following steps show how to start the smartclock crystal oscillator in software: 1. configure the xtal3 and xtal4 pins for analog i/o. 2. set smartclock to crystal mode (xmode = 1). 3. disable automatic gain control (a gcen) and enable bias doubling (b iasx2) for fast crystal startup. 4. set the desired loading capacitance (rtc0xcf). 5. enable power to the smartclock oscillato r circuit (rtc0en = 1). 6. wait 20 ms. 7. poll the smartclock clock valid bit (clkvld) until th e crystal oscillator stabilizes. 8. poll the smartclock load capacitance ready bit (loadrdy) until the load capacitance reaches its programmed value. 9. enable automatic gain contro l (agcen) and disable bias doub ling (biasx2) for maximum power savings. 10.enable the smartclock missing clock detector. 11. wait 2 ms. 12.clear the pmu0cf wake-up source flags. ? in crystal mode, the smartclock osc illator may be driven by an extern al cmos clock. the cmos clock should be applied to xtal3. xtal34 should be left fl oating. in this mode, the ex ternal cmos clock is ac coupled into the smartclock and should have a minimum voltage swing of 400 mv. the cmos clock sig - nal voltage should not exceed vdd or drop below gnd. bias levels clos er to vdd will result in lower i/o power consumption be cause the xtal3 pin has a built-in weak pull-up. the smartclock oscillator should be configured to its lowest bias setting with agc disabled. the clkvld bit is indeterminate when using a cmos clock, however, the oscfail bit may be checked 2 ms after smartclock os cillator is powered on to ensure that there is a valid clock on xtal3. www.datasheet.in
c8051f99x-c8051f98x 202 rev. 1.0 20.2.2. using the smartclock oscillator in self-oscillate mode when using self-oscillate mode, the xtal3 and xtal4 pins are inte rnally shorted toge ther. the following steps show how to configure smartclo ck for use in self-oscillate mode: 1. set smartclock to self-osc illate mode (xmode = 0). 2. set the desired oscillation frequency: ? for oscillation at about 20 khz, set biasx2 = 0. ? for oscillation at about 40 khz, set biasx2 = 1. 3. the oscillator starts oscillating instantaneously. 4. fine tune the oscillation frequency by adjusting the load capacitance (rtc0xcf). 20.2.3. using the low frequency oscillator (lfo) the low frequency oscillator provides an ultra low power, on-chip clo ck source to the smartclock. the typical frequency of oscillation is 16.4 khz 20%. no external components are required to use the lfo and the xtal3 and xtal4 pins do not need to be shorted together. the following steps show how to configure smartclock for use with the lfo: 1. enable and select the low fr equency oscillator (lfoen = 1). 2. the lfo starts oscillating instantaneously. when the lfo is enabled, the smartclock oscillator increm ents bit 1 of the 32-bit timer (instead of bit 0). this effectively multiplies the lfo frequency by 2, making the rtc timebase behave as if a 32.768 khz crystal is connected at the output. www.datasheet.in
rev. 1.0 203 c8051f99x-c8051f98x 20.2.4. programmable load capacitance the programmable load capacitance has 16 values to support crystal osc illators with a wide range of rec - ommended load capacitance. if automatic load capaci tance stepping is enabled, the crystal load capaci - tors start at the smallest setting to allow a fast startup time, then slowly increase the capacitance until the final programmed value is reached. the final programme d loading capacitor value is specified using the loadcap bits in the rtc0xcf register. the loadc ap setting specifies the amount of on-chip load capacitance and does not include any stray pcb capa citance. once the final programmed loading capaci - tor value is reached, the loadrdy flag will be set by hardware to logic 1. when using the smartclock oscillato r in self-oscillate mode, the prog rammable load capacitance can be used to fine tune the oscillation fr equency. in most cases, increasing the load capacitor value will result in a decrease in oscillation frequency. ta b l e 20.2 shows the crystal load capaci tance for various settings of loadcap. table 20.2. smartclock load capacitance settings loadcap crystal load capacitance equivalent capacitance seen on xtal3 and xtal4 0000 4.0 pf 8.0 pf 0001 4.5 pf 9.0 pf 0010 5.0 pf 10.0 pf 0011 5.5 pf 11.0 pf 0100 6.0 pf 12.0 pf 0101 6.5 pf 13.0 pf 0110 7.0 pf 14.0 pf 0111 7.5 pf 15.0 pf 1000 8.0 pf 16.0 pf 1001 8.5 pf 17.0 pf 1010 9.0 pf 18.0 pf 1011 9.5 pf 19.0 pf 1100 10.5 pf 21.0 pf 1101 11.5 pf 23.0 pf 1110 12.5 pf 25.0 pf 1111 13.5 pf 27.0 pf www.datasheet.in
c8051f99x-c8051f98x 204 rev. 1.0 20.2.5. automatic gain control (crystal mode only) and smartclock bias doubling automatic gain control allows the sm artclock oscillator to trim the osc illation amplitude of a crystal in order to achieve the lowest possible power consumpt ion. automatic gain control automatically detects when the oscillation amplitude has r eached a point where it safe to redu ce the drive curren t, therefore, it may be enabled during crystal startup. it is recomm ended to enable automatic gain control in most sys - tems which use the smartclock oscillator in crystal mode. the following are recommended crystal spec - ifications and operating c onditions when automatic gain control is enabled: ? esr < 50 k ? ? load capacitance < 10 pf ? supply voltage < 3.0 v ? temperature > ?20 c when using automatic gain control, it is recommended to perform an osc illation robustness test to ensure that the chosen crystal will oscillate under the worst case condition to which th e system will be exposed. the worst case condition that should result in the least robust oscilla tion is at the following system condi - tions: lowest temperature, highest supply voltage, highest esr, highest load capacitance, and lowest bias current (agc enabled, bias double disabled). to perform the oscillation robustness test, the smartc lock oscillator should be enabled and selected as the system clock source. next, the sysclk signal should be routed to a po rt pin configured as a push-pull digital output. the positive duty cycle of the output cl ock can be used as an indi cator of oscillation robust - ness. as shown in figure 20.2 , duty cycles less than 55% indicate a robust oscillation. as the duty cycle approaches 60%, oscillation becomes less reliable and the risk of clock failure increases. increasing the bias current (by disabling agc) will always improv e oscillation robustness a nd will reduce the output clock?s duty cycle. this test should be performed at th e worst case system conditions, as results at very low temperatures or high supply voltage will vary from results taken at room temperature or low supply voltage. figure 20.2. interpreting oscillation robustness (duty cycle) test results as an alternative to performing the oscilla tion robustness test, automatic ga in control may be disabled at the cost of increased power consumption (approximately 200 na). disabling automatic gain control will provide the crystal oscillator with high er immunity against exte rnal factors which may lead to clock failure. automatic gain control must be di sabled if using the smartclock os cillator in self-oscillate mode. ta b l e 20.3 shows a summary of the oscillator bias settings . the smartclock bias doubling feature allows the self-oscillation frequency to be increased (alm ost doubled) and allo ws a higher crystal drive strength in crystal mode. high crystal drive strength is recommend ed when the crystal is exposed to poor environmen - tal conditions such as excessive moisture. smartc lock bias doubling is en abled by setting biasx2 (rtc0xcn.5) to 1. duty cycle 25% 55% 60% safe operating zone low risk of clock failure high risk of clock failure www.datasheet.in
rev. 1.0 205 c8051f99x-c8051f98x . table 20.3. smartclock bias settings mode setting power consumption crystal bias double off, agc on lowest 600 na bias double off, agc off low 800 na bias double on, agc on high bias double on, agc off highest self-oscillate bias double off low bias double on high www.datasheet.in
c8051f99x-c8051f98x 206 rev. 1.0 20.2.6. missing smartclock detector the missing smartclock detector is a one-shot circ uit enabled by setting mc lken (rtc0cn.6) to 1. when the smartclock missing clock detector is enabled, oscfail (rtc 0cn.5) is set by hardware if smartclock oscillator remains high or low for more than 100 s. a smartclock missing clock detector timeout can trigger an interrupt, wake the device from a low power mode, or reset the device. see section ?13. interrupt handler? on page 137 , section ?15. power manage - ment? on page 161 , and section ?18. reset sources? on page 179 for more information. note: the smartclock missing clock detector should be disabled when making changes to the oscillator settings in rtc0xcn. 20.2.7. smartclock oscillator crystal valid detector the smartclock oscillator crystal valid detector is an oscillation amplit ude detector circuit used during crystal startup to dete rmine when oscillation has started and is ne arly stable. the output of this detector can be read from the clkvld bit (rtx0xcn.4). notes: 1. the clkvld bit has a blanking interval of 2 ms. during the first 2 ms after turning on the crystal oscillator, the output of clkvld is not valid. 2. this smartclock crystal valid detector (clkvld) is not intended for detecting an oscillator failure. the missing smartclock detector (clkfail) should be used for this purpose. 20.3. smartclock timer and alarm function the smartclock timer is a 32-bit counter that, when running (rtc0tr = 1), is incremented every smartclock oscillator cycle. the timer has an alarm f unction that can be set to generate an interrupt, wake the device from a low power mode, or reset the device at a specific time. see section ?13. interrupt handler? on page 137 , section ?15. power management? on page 161 , and section ?18. reset sources? on page 179 for more information. the smartclock timer includes an auto reset feature, which automatically resets the timer to zero one smartclock cycle after the alarm signal is deassert ed. when using auto reset, the alarm match value should always be set to 2 counts less than the desired match value. when using the lfo in combination with auto reset, the right-justified alarm match value should be set to 4 counts less than the desired match value. auto reset can be enabled by writing a 1 to alrm (rtc0cn.2). 20.3.1. setting and reading the smartclock timer value the 32-bit smartclock timer can be set or read using the six capturen internal registers. note that the timer does not need to be stopped before reading or setting its value. the following steps can be used to set the timer value: 1. write the desired 32-bit set value to the capturen registers. 2. write 1 to rtc0set. this will transfer the contents of the capturen regi sters to the smartclock timer. 3. operation is complete when rtc0 set is cleared to 0 by hardware. the following steps can be used to read the current timer value: 1. write 1 to rtc0cap. this will transfer the contents of the timer to th e capturen registers. 2. poll rtc0cap until it is cleared to 0 by hardware. 3. a snapshot of the timer value can be read from the capturen registers www.datasheet.in
rev. 1.0 207 c8051f99x-c8051f98x 20.3.2. setting a smartclock alarm the smartclock alarm function compares the 32-bit value of smartclock timer to the value of the alarmn registers. an alarm event is triggered if the sm artclock timer is equal to the alarmn registers. if auto reset is enabled, the 32-b it timer will be cleared to zero o ne smartclock cycle after the alarm event. the smartclock alarm event can be configured to reset the mcu, wake it up from a low power mode, or generate an interrupt. see section ?13. interrupt hand ler? on page 137 , section ?15. power management? on page 161 , and section ?18. reset sources? on page 179 for more information. the following steps can be used to set up a smartclock alarm: 1. disable smartclock alarm events (rtc0aen = 0). 2. set the alarmn registers to the desired value. 3. enable smartclock alar m events (rtc0aen = 1). ? notes: 1. the alrm bit, which is used as the smartclock alarm ev ent flag, is cleared by disabling smartclock alarm events (rtc0aen = 0). 2. if autoreset is disabled, disabling (rtc0aen = 0) then re-enabling alarm events (rtc0aen = 1) after a smartclock alarm without modifying alarmn registers will automatically schedule the next alarm after 2^32 smartclock cycles (approximately 36 hours using a 32.768 khz crystal). 3. the smartclock alarm event flag will remain asserted for a maximum of one smar tclock cycle. see section ?15. power management? on page 161 for information on how to capture a smartclock alarm event using a flag which is not automatically cleared by hardware. www.datasheet.in
c8051f99x-c8051f98x 208 rev. 1.0 20.3.3. software considerations for using the smartclock timer and alarm the smartclock timer and alarm have two operating modes to suit varying applications. the two modes are described below: mode 1: ? the first mode uses the smartclock timer as a perpet ual timebase which is never reset to zero. every 36 hours, the timer is allowed to overflow without being stopped or disrupted. the alarm interval is software managed and is added to the alrmn registers by software after each alarm. this allows the alarm match value to always stay ahead of the timer by one software managed interval. if software uses 32-bit unsigned addition to increment the alarm match value, then it does not need to handle ov erflows since both the timer and the alarm match value will overflow in the same manner. this mode is ideal for applications which have a long alarm interval (e.g., 24 or 36 hours) and/or have a need for a perpetual timebase. an example of an application that needs a perpetual timebase is one whose wake-up interval is constant ly changing. for these applications, software can keep track of the number of timer overflows in a 16-bit variable, extendi ng the 32-bit (36 hour) timer to a 48-bit (272 year) perpetual timebase. mode 2: ? the second mode uses the smartclock timer as a general purpose up counter which is auto reset to zero by hardware after each alarm. the alarm interval is managed by hardware and stored in the alrmn regis - ters. software only needs to set the alarm interval once during device initialization. after each alarm, soft - ware should keep a count of the number of alarms th at have occurred in order to keep track of time. this mode is ideal for applications that require minimal software intervention and/or have a fixed alarm interval. this mode is the most power effici ent since it requires less cpu time per alarm. www.datasheet.in
rev. 1.0 209 c8051f99x-c8051f98x smartclock address = 0x04 internal register definition 20.4. rtc0cn: smartclock control bit 7 6 5 4 3 2 1 0 name rtc0en mclken oscfail rtc0tr rtc0aen alrm rtc0set rtc0cap type r/w r/w r/w r/w r/w r/w r/w r/w reset 00varies00000 bit name function 7 rtc0en smartclock enable. enables/disables the smartclock oscillator and associated bias currents. 0: smartclock oscillator disabled. 1: smartclock o scillator enabled. 6 mclken missing smartclock detector enable. enables/disables the missing smartclock detector. 0: missing smartclock detector disabled. 1: missing smartclock detector enabled. 5 oscfail smartclock oscillator fail event flag. set by hardware when a missing smartclock detector timeout occurs. must be cleared by software. the value of this bit is not defined when the smartclock ? oscillator is disabled. 4 rtc0tr smartclock timer run control. controls if the smartclock timer is running or stopped (holds current value). 0: smartclock timer is stopped. 1: smartclock timer is running. 3 rtc0aen smartclock alarm enable. enables/disables the smartclock alarm function. also clears the alrm flag. 0: smartclock alarm disabled. 1: smartclock alarm enabled. 2 alrm smartclock alarm event flag and auto reset enable. reads return the state of the alarm event flag. writes enable/disable the ? auto reset function. read: 0: smartclock alarm event flag is de-asserted. 1: smartclock alarm event flag is asserted. write: 0: disable auto reset. 1: enable auto reset. 1 rtc0set smartclock timer set. writing 1 initiates a smartclock timer set operation. this bit is cleared to 0 by hardware to indi - cate that the timer set operation is complete. 0 rtc0cap smartclock timer capture. writing 1 initiates a smartclock timer capture operat ion. this bit is cleared to 0 by hardware to indicate that the timer capture operation is complete. note: the alrm flag will remain asserted for a maximum of one smartc lock cycle. see section ?power management? on page 161 for information on how to capture a smartclock alarm event using a flag which is not automatically cleared by hardware. www.datasheet.in
c8051f99x-c8051f98x 210 rev. 1.0 smartclock address = 0x05 internal register definition 20.5. rtc0xcn: smartclock oscillator control bit 7 6 5 4 3 2 1 0 name agcen xmode biasx2 clkvld lfoen type r/wr/wr/wrrrrr reset 00000000 bit name function 7 agcen smartclock oscillator automatic gain control (agc) enable. 0: agc disabled. 1: agc enabled. 6 xmode smartclock oscillator mode. selects crystal or self oscillate mode. 0: self-oscillate mode selected. 1: crystal mode selected. 5 biasx2 smartclock oscillator bias double enable. enables/disables the bias double feature. 0: bias double disabled. 1: bias double enabled. 4 clkvld smartclock oscillator crystal valid indicator. indicates if oscillation amplitude is su fficient for maintaining oscillation. 0: oscillation has not started or oscillation amplitude is too low to maintain oscillation. 1: sufficient oscillati on amplitude detected. 3 lfoen low frequency oscillator enable and select. overrides xmode and selects the internal low frequency oscillator (lfo) as the smartclock osc illator source. 0: xmode determines smartclock oscillator source. 1: lfo enabled and selected as smartclock oscillator source. 2:0 unused read = 000b; write = don?t care. www.datasheet.in
rev. 1.0 211 c8051f99x-c8051f98x smartclock address = 0x06 internal register definition 20.6. rtc0xcf: smartclock osc illator configuration bit 7 6 5 4 3 2 1 0 name autostp loadrdy loadcap type r/w r r r r/w reset 0 0 0 0 varies varies varies varies bit name function 7 autostp automatic load capacitance stepping enable. enables/disables automatic load capacitance stepping. 0: load capacitance stepping disabled. 1: load capacitance stepping enabled. 6 loadrdy load capacitance ready indicator. set by hardware when the load capacitance matches the programmed value. 0: load capacitance is currently stepping. 1: load capacitance has reached it programmed value. 5:4 unused read = 00b; write = don?t care. 3:0 loadcap load capacitance programmed value. holds the user?s desired value of the load capacitance. see ta b l e 20.2 on page 203 . www.datasheet.in
c8051f99x-c8051f98x 212 rev. 1.0 smartclock addresses: capture0 = 0x00; capture1 = 0x01; capture2 =0x02; capture3: 0x03. smartclock addresses: alarm0 = 0x08; alarm1 = 0x09; alarm2 = 0x0a; alarm3 = 0x0b internal register definition 20.7. capturen: smartclock timer capture bit 7 6 5 4 3 2 1 0 name capture[31:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:0 capture[31:0] smartclock timer capture. these 4 registers (capture3?capture0) are used to read or set the 32-bit smartclock timer. data is transferred to or from the smartclock timer when the rtc0set or rtc0cap bits are set. note: the least significant bit of the timer capture value is in capture0.0. internal register definition 20.8. alarmn: smartclock al arm programmed value bit 7 6 5 4 3 2 1 0 name alarm[31:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:0 alarm[31:0] smartclock alarm programmed value. these 4 registers (alarm3?alarm0) are used to set an alarm event for the smartclock timer. the smartclock alarm should be disabled (rtc0aen=0) when updating these registers. note: the least significant bit of the alarm programmed value is in alarm0.0. www.datasheet.in
rev. 1.0 213 c8051f99x-c8051f98x 21. port input/output digital and analog resources are available through 16 or 17 i/o pins. port pins are organized as three byte- wide ports. port pins p0.0?p1.7 can be defined as digita l or analog i/o. digital i/o pins can be assigned to one of the internal digital resources or used as ge neral purpose i/o (gpio). analog i/o pins are used by the internal analog resources. p2.7 can be used as gpio and is shared with the c2 interface data signal (c2d). see section ?27. c2 interface? on page 317 for more details. the designer has complete control over which digital and analog functions are as signed to individual port pins, limited only by the nu mber of physical i/o pins. this resour ce assignment flexibility is achieved through the use of a priority crossbar decoder. see section 21.3 for more information on the crossbar. all port i/os can tolerate voltages up to the supply rail when used as digital inputs or open-drain outputs. for port i/os configured as push-pull outputs, current is sourced from the v dd supply. port i/os used for analog functions can operate up to the v dd supply voltage. see section 21.1 for more information on port i/o operating modes and the electrical specificatio ns chapter for detailed el ectrical specifications. figure 21.1. port i/o functional block diagram xbr0, xbr1, xbr2, pnskip registers digital crossbar priority decoder 2 p0 i/o cells p0.0 p0.7 8 port match p0mask, p0mat p1mask, p1mat uart (internal digital signals) highest priority lowest priority sysclk 2 smbus t0, t1 2 4 pca 4 cp0 output spi0 4 p1 i/o cells p1.0 p1.7* 8 (port latches) p0 (p0.0-p0.7) (p1.0-p1.7) 8 8 p1 p2 i/o cell p2 (p2.7) 1 1 pnmdout, pnmdin registers p2.7 to analog peripherals (adc0, cp0, and cp1 inputs, vref, iref0, agnd) external interrupts ex0 and ex1 *p1.5 is not available on 20-pin devices. www.datasheet.in
c8051f99x-c8051f98x 214 rev. 1.0 21.1. port i/o modes of operation port pins p0.0?p1.7 use the port i/o cell shown in figure 21.2 . each port i/o cell can be configured by software for analog i/o or digital i/o using the pnmdin re gisters. on reset, all port i/o cells default to a dig - ital high impedance state with weak pull-ups enabled. 21.1.1. port pins configured for analog i/o any pins to be used as comparator or adc input, oscillator input/outp ut, or agnd, vref, or current ref - erence output should be configured for analog i/o (pnmdin.n = 0). when a pin is configured for analog i/o, its weak pullup and digital receiver are disabled. in most cases, software should also disable the digital output drivers. port pins configured for analog i/o will always read back a value of 0 regardless of the actual voltage on the pin. configuring pins as analog i/o saves power and isolates the port pin from digital interference. port pins configured as digital inputs may still be used by analog peripherals; howe ver, this practice is not recom - mended and may result in measurement errors. 21.1.2. port pins configured for digital i/o any pins to be used by digital peripherals (uart, sp i, smbus, etc.), external digital event capture func - tions, or as gpio should be co nfigured as digital i/o (pnmdin.n = 1). for digital i/o pins, one of two output modes (push-pull or open-drain) must be selected using the pnmdout registers. push-pull outputs (pnmdout.n = 1) drive the port pad to the vdd or gnd supply rails based on the out - put logic value of the port pin. open-drain outputs have the high side driver disabled; therefore, they only drive the port pad to gnd when the output logic valu e is 0 and become high impedance inputs (both high and low drivers turned off) when the output logic value is 1. when a digital i/o cell is placed in the high impedance st ate, a weak pull-up transistor pulls the port pad to the vdd supply voltage to ensure th e digital input is at a defined logic state. weak pull-ups are disabled when the i/o cell is driven to gnd to minimize power consumption and may be globally disabled by setting weakpud to 1. the user must ensure th at digital i/o are always internally or externally pu lled or driven to a valid logic state. port pins configured for digital i/o always read back the logic state of the port pad, regardless of the output logic value of the port pin. figure 21.2. port i/o cell block diagram gnd vdd/dc+ vdd/dc+ (weak) port pad to/from analog peripheral pnmdin.x (1 for digital) (0 for analog) pn.x ? output logic value (port latch or crossbar) xbare (crossbar enable) pn.x ? input logic value (reads 0 when pin is configured as an analog i/o) pnmdout.x (1 for push-pull) (0 for open-drain) weakpud (weak pull-up disable) www.datasheet.in
rev. 1.0 215 c8051f99x-c8051f98x 21.1.3. interfacing port i/o to 5 v logic all port i/o have internal esd protection diodes to prevent the pin voltage from exceeding the v dd supply. the port i/o pins are not 5v tolerant and require level translators to interface to 5v logic. 21.1.4. increasing port i/o drive strength port i/o output drivers support a high and low drive st rength; the default is low drive strength. the drive strength of a port i/o can be configured using the pndrv registers. see section ?4. electrical characteris - tics? on page 46 for the difference in output drive strength between the two modes. 21.2. assigning port i/o pins to analog and digital functions port i/o pins p0.0?p1.7 can be assigned to various a nalog, digital, and external interrupt functions. the port pins assuaged to analog functions should be conf igured for analog i/o and port pins assuaged to dig - ital or external interrupt functions should be configured for digital i/o. 21.2.1. assigning port i/o pins to analog functions ta b l e 21.1 shows all available analog function s that need port i/o assignments. port pins selected for these analog functions should have their digital dr ivers disabled (pnmdout.n = 0 and port latch = 1) and their corresponding bit in pnskip set to 1. this reserves the pin for use by the analog function and does not allow it to be claimed by the crossbar. ta b l e 21.1 shows the potential mapping of port i/o to each analog function. table 21.1. port i/o assignment for analog functions analog function potentially assignable port pins registers used for assignment adc input p0.1?p0.7, p1.2?p1.4 adc0mx, pnskip comparator0 input p1.0, p1.1 cpt0mx, pnskip voltage reference (vref0) p0.0 ref0cn, pnskip analog ground reference (agnd) p0.1 ref0cn, pnskip current reference (iref0) p0.7 iref0cn, pnskip external oscillator input (xtal1) p0.2 oscxcn, pnskip external oscillato r output (xtal2) p0.3 oscxcn, pnskip smartclock oscillator input (xtal3) p1.6 rtc0cn, pnskip smartclock oscillato r output (xtal4) p1.7 rtc0cn, pnskip www.datasheet.in
c8051f99x-c8051f98x 216 rev. 1.0 21.2.2. assigning port i/o pins to digital functions any port pins not assigned to analog functions may be assigned to digital functi ons or used as gpio. most digital functions rely on the crossbar for pin assi gnment; however, some digital functions bypass the crossbar in a manner similar to the analog functions listed above. port pins used by these digital func - tions and any port pins selected for use as gpio should have their corresponding bit in pnskip set to 1. ta b l e 21.2 shows all available digital functions and the potential mapping of port i/o to each digital function. 21.2.3. assigning port i/o pins to external digital event capture functions external digital event captur e functions can be used to trigger an interrupt or wake the device from a low power mode when a transition occurs on a digital i/o pin. the digital event capture functions do not require dedicated pins and will function on both gpio pins (pnskip = 1) and pi ns in use by the crossbar (pnskip = 0). external digital even capt ure functions cannot be used on pins configured for analog i/o. ta b l e 21.3 shows all available external digital event capture functions. table 21.2. port i/o assignment for digital functions digital function potentially assignable port pins sfr(s) used for assignment uart0, spi0, smbus, cp0 outputs, system clock out - put, pca0, timer0 and timer1 external inputs. any port pin available for assignment by the crossbar. this includes p0.0?p1.7 pins which have their pnskip bit set to 0. note: the crossbar will always assign uart0 and spi1 pins to fixed locations. xbr0, xbr1, xbr2 any pin used for gpio p0.0?p1.7, p2.7 p0skip, p1skip table 21.3. port i/o assignment for external digital event capture functions digital function potentially assignable port pins sfr(s) used for assignment external interrupt 0 p0.0?p0.7 it01cf external interrupt 1 p0.0?p0.7 it01cf port match p0.0?p1.7 p0mask, p0mat p1mask, p1mat www.datasheet.in
rev. 1.0 217 c8051f99x-c8051f98x 21.3. priority crossbar decoder the priority cro ssbar decoder ( figure 21.3 ) assigns a priority to each i/o function, starting at the top with uart0. when a digital resource is selected, the leas t-significant unassigned port pin is assigned to that resource (excluding uart0, which is a lways at pins 4 and 5). if a port pin is assigned, the crossbar skips that pin when assigning the next se lected resource. additionally, the crossbar will skip port pins whose associated bits in the pnskip registers are set. the pn skip registers allow software to skip port pins that are to be used for analog input, dedicated functions, or gpio. important note on crossbar configuration: if a port pin is claimed by a peripheral without use of the crossbar, its corresponding pnskip bit should be set. this applies to th e vref signal, external oscillator pins (xtal1, xtal2), the adc?s external conversion st art signal (cnvstr), emif control signals, and any selected adc or comparator inputs. the pnskip register s may also be used to skip pins to be used as gpio. the crossbar skips selected pins as if they were already assigned, and moves to the next unas - signed pin. figure 21.3 shows all the possible pins available to each peripheral. figure 21.4 shows the crossbar decoder priority in an example configuration with no port pins skipped. figure 21.5 shows the same crossbar example with pins p0.2, p0.3, p1.0, and p1.1 skipped. figure 21.3. peripheral availability on port i/o pins vref agnd xtal1 xtal2 cnvstr iref0 cp0+ cp0- xtal3 xtal4 c2d 012345670123456701234567 sck miso mosi nss* cp0 cp0a t1 *nss is only pinned out in 4-wire spi mode port pin potentially available to peripheral sf signals eci t0 special function signals are not assigned by the crossbar. when these signals are enabled, the crossbar must be manually configured to skip their corresponding port pins. pin not available for crossbar functions p2.0 - p2.6 not available on c8051f98x-c8051f99x devices cex2 cex0 cex1 scl sf signals sysclk rx0 sda p2 p1 p0 pin i/o tx0 www.datasheet.in
c8051f99x-c8051f98x 218 rev. 1.0 figure 21.4. crossbar priority decoder in example configuration (no pins skipped) figure 21.5. crossbar priority decoder in example configuration (4 pins skipped) vref agnd xtal1 xtal2 cnvstr iref0 cp0+ cp0- xtal3 xtal4 c2d 012345670123456701234567 sck miso mosi nss* cp0 cp0a t1 000000000000000000000000 *nss is only pinned out in 4-wire spi mode port pin assigned to peripheral by the crossbar sf signals eci t0 special function signals are not assigned by the crossbar. when these signals are enabled, the crossbar must be manually configured to skip their corresponding port pins. p1skip[0:7] note: in this example, cp0, cp0a, and sysclk are not selected in the crossbar. p2.0 - p2.6 not available on c8051f98x-c8051f99x devices cex2 cex0 cex1 scl sf signals sysclk rx0 sda p2 p1 p0 p2skip[0:7] pin i/o tx0 p0skip[0:7] pin not available for crossbar functions vref agnd xtal1 xtal2 cnvstr iref0 cp0+ cp0- xtal3 xtal4 c2d 012345670123456701234567 sck miso mosi nss* cp0 cp0a t1 001100001100000000000000 *nss is only pinned out in 4-wire spi mode p2skip[0:7] note: in this example, cp0, cp0a, and sysclk are not selected in the crossbar. pin i/o tx0 p0skip[0:7] p2 p1 p0 pin not available for crossbar functions p2.0 - p2.6 not available on c8051f98x-c8051f99x devices cex2 cex0 cex1 scl sf signals sysclk rx0 sda port pin assigned to peripheral by the crossbar sf signals eci t0 special function signals are not assigned by the crossbar. when these signals are enabled, the crossbar must be manually configured to skip their corresponding port pins. p1skip[0:7] www.datasheet.in
rev. 1.0 219 c8051f99x-c8051f98x registers xbr0, xbr1, and xbr2 are used to assign the digital i/o resources to the physical i/o port pins. note that when the smbus is selected, the cr ossbar assigns both pins associated with the smbus (sda and scl); when either uart is selected, the cr ossbar assigns both pins associated with the uart (tx and rx). uart0 pin assignments are fixed for boot loading purposes: uart tx0 is always assigned to p0.4; uart rx0 is always assigned to p0.5. standar d port i/os appear contiguously after the prioritized functions have been assigned. notes: 1. the crossbar must be enabled (xbare = 1) before any port pin is used as a digital output. port output drivers are disabled while the crossbar is disabled. 2. when smbus is selected in the crossbar, the pins associated with sda and scl will automatically be forced into open-drain output mode regardless of the pnmdout setting. 3. spi0 can be operated in either 3-wire or 4-wire modes, depending on the state of the nssmd1-nssmd0 bits in register spi0cn. the nss signal is only routed to a po rt pin when 4-wire mode is selected. when spi0 is selected in the crossbar, the spi0 mode (3-wire or 4-wire) will affect the pinout of all digital functions lower in priority than spi0. 4. for given xbrn, pnskip, and spincn register settings, one can determine the i/o pin-out of the device using figure 21.3. 5. on 20-pin devices, p1.4 should be skipped in the crossbar. it is not available as a device pin. www.datasheet.in
c8051f99x-c8051f98x 220 rev. 1.0 sfr page = 0x0; sfr address = 0xe1 sfr definition 21.1. xbr0: port i/o crossbar register 0 bit 7 6 5 4 3 2 1 0 name cp0ae cp0e syscke smb0e spi0e urt0e type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:6 unused read = 00b. write = don?t care. 5 cp0ae comparator0 asynchronous output enable. 0: asynchronous cp0 output unavailable at port pin. 1: asynchronous cp0 output routed to port pin. 4 cp0e comparator0 output enable. 0: cp1 output unavailable at port pin. 1: cp1 output routed to port pin. 3 syscke sysclk output enable. 0: sysclk output unavailable at port pin. 1: sysclk output routed to port pin. 2 smb0e smbus i/o enable. 0: smbus i/o unavailable at port pin. 1: sda and scl routed to port pins. 1 spi0e spi0 i/o enable. 0: spi0 i/o unavailable at port pin. 1: sck, miso, and mosi (for spi0) routed to port pins. nss (for spi0) routed to port pin only if spi0 is configured to 4-wire mode. 0 urt0e uart0 output enable. 0: uart i/o unavailable at port pin. 1: tx0 and rx0 routed to port pins p0.4 and p0.5. note: spi0 can be assigned either 3 or 4 port i/o pins. www.datasheet.in
rev. 1.0 221 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xe2 sfr definition 21.2. xbr1: port i/o crossbar register 1 bit 7 6 5 4 3 2 1 0 name t1e t0e ecie pca0me[2:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:6 unused read = 00b; write = don?t care. 5 t1e timer1 input enable. 0: t1 input unavailable at port pin. 1: t1 input routed to port pin. 4 t0e timer0 input enable. 0: t0 input unavailable at port pin. 1: t0 input routed to port pin. 3 ecie pca0 external counter input (eci) enable. 0: pca0 external counter input unavailable at port pin. 1: pca0 external counter input routed to port pin. 2:0 pca0me pca0 module i/o enable. 000: all pca0 i/o unavailable at port pin. 001: cex0 routed to port pin. 010: cex0, cex1 routed to port pins. 011: cex0, cex1, cex2 routed to port pins. 100: reserved. 101: reserved. 110: reserved. 111: reserved. www.datasheet.in
c8051f99x-c8051f98x 222 rev. 1.0 sfr page = 0x0; sfr address = 0xe3 sfr definition 21.3. xbr2: port i/o crossbar register 2 bit 7 6 5 4 3 2 1 0 name weakpud xbare type r/w r/w r/w r/w r/w r/w r/w r/w reset 0 0000000 bit name function 7 weakpud port i/o weak pullup disable. 0: weak pullups enabled (except for port i/o pins configured for analog mode). 6 xbare crossbar enable. 0: crossbar disabled. 1: crossbar enabled. 5:0 unused read = 000000b; write = don?t care. note: the crossbar must be enabled (xbare = 1) to use any port pin as a digital output. www.datasheet.in
rev. 1.0 223 c8051f99x-c8051f98x 21.4. port match port match functionality allows system events to be tr iggered by a logic value change on p0 or p1. a soft - ware controlled value stored in the pnmat registers sp ecifies the expected or normal logic values of p0 and p1. a port mismatch event occurs if the logic levels of the port?s input pins no longer match the soft - ware controlled value. this allows software to be notified if a certain change or pattern occurs on p0 or p1 input pins regardless of the xbrn settings. the pnmask registers can be used to individually select which p0 a nd p1 pins should be compared against the pnmat registers. a port mismatch event is generated if (p0 & p0mask) does not equal (pnmat & p0mask) or if (p1 & p1mask) does not equal (pnmat & p1mask). a port mismatch event may be used to generate an interrupt or wake the device from a low power mode. see section ?13. interrupt handler? on page 137 and section ?15. power management? on page 161 for more details on interrupt and wake-up sources. sfr page= 0x0; sfr address = 0xc7 sfr page= 0x0; sfr address = 0xd7 sfr definition 21.4. p0mask: port0 mask register bit 7 6 5 4 3 2 1 0 name p0mask[7:0] type r/w reset 00000000 bit name function 7:0 p0mask[7:0] port0 mask value. selects the p0 pins to be compared with the corresponding bits in p0mat. 0: p0.n pin pad logic value is ignored and cannot cause a port mismatch event. 1: p0.n pin pad logic value is compared to p0mat.n. sfr definition 21.5. p0mat: port0 match register bit 7 6 5 4 3 2 1 0 name p0mat[7:0] type r/w reset 11111111 bit name function 7 : 0 p0mat[7:0] port 0 match value. match comparison value used on port 0 for bits in p0mask which are set to 1. 0: p0.n pin logic value is compared with logic low. 1: p0.n pin logic value is compared with logic high. www.datasheet.in
c8051f99x-c8051f98x 224 rev. 1.0 sfr page= 0x0; sfr address = 0xbf sfr page = 0x0; sfr address = 0xcf sfr definition 21.6. p1mask: port1 mask register bit 7 6 5 4 3 2 1 0 name p1mask[7:0] type r/w reset 00000000 bit name function 7:0 p1mask[7:0] port 1 mask value. selects p1 pins to be compared to the corresponding bits in p1mat. 0: p1.n pin logic value is ignored and cannot cause a port mismatch event. 1: p1.n pin logic value is compared to p1mat.n. sfr definition 21.7. p1mat: port1 match register bit 7 6 5 4 3 2 1 0 name p1mat[7:0] type r/w reset 11111111 bit name function 7:0 p1mat[7:0] port 1 match value. match comparison value used on port 1 for bits in p1mask which are set to 1. 0: p1.n pin logic value is compared with logic low. 1: p1.n pin logic value is compared with logic high. www.datasheet.in
rev. 1.0 225 c8051f99x-c8051f98x 21.5. special function registers for accessing and configuring port i/o all port i/o are accessed through corresponding specia l function registers (sfrs) that are both byte addressable and bit addressable. wh en writing to a port, the value written to the sfr is latched to main - tain the output data value at each pin. when reading, the logic levels of the port's input pins are returned regardless of the xbrn settings (i.e., even when the pi n is assigned to another signal by the crossbar, the port register can always read its corresponding port i/ o pin). the exception to this is the execution of the read-modify-write instructio ns that target a port latch register as the destination. the read-modify-write instructions when operating on a port sfr are the fo llowing: anl, orl, xrl, jb c, cpl, inc, dec, djnz and mov, clr or setb, when the destination is an indi vidual bit in a port sfr. for these instructions, the value of the latch register (not the pin) is read, modified, and written back to the sfr. each port has a corresponding pnskip register which allo ws its individual port pins to be assigned to dig - ital functions or skipped by the crossbar. all port pins used for analog functions, gpio, or dedicated digital functions such as the emif shou ld have their pnskip bit set to 1. the port input mode of the i/o pins is defined usi ng the port input mode registers (pnmdin). each port cell can be configured for analog or digital i/o. this selection is required even for the digital resources selected in the xbrn registers, and is not automatic. th e only exception to this is p2.7, which can only be used for digital i/o. the output driver characteristics of the i/o pins ar e defined using the port output mode registers (pnmd - out). each port output driver can be configured as either open drain or push- pull. this selection is required even for the digital resources selected in the xbrn registers, and is not automatic. the only exception to this is the smbus (sda, scl) pins, which are configured as open-drain regardless of the pnmdout settings. the drive strength of the output driv ers are controlled by the port drive strength (pndrv) registers. the default is low drive strength. see section ?4. electrical characteristics? on page 46 for the difference in out - put drive strength between the two modes. www.datasheet.in
c8051f99x-c8051f98x 226 rev. 1.0 sfr page = all; sfr address = 0x80; bit-addressable sfr page= 0x0; sfr address = 0xd4 sfr definition 21.8. p0: port0 bit 7 6 5 4 3 2 1 0 name p0[7:0] type r/w reset 11111111 bit name description write read 7:0 p0[7:0] port 0 data. sets the port latch logic value or reads the port pin logic state in port cells con - figured for digital i/o. 0: set output latch to logic low. 1: set output latch to logic high. 0: p0.n port pin is logic low. 1: p0.n port pin is logic high. sfr definition 21.9. p0skip: port0 skip bit 7 6 5 4 3 2 1 0 name p0skip[7:0] type r/w reset 00000000 bit name function 7:0 p0skip[7:0] port 0 crossbar skip enable bits. these bits select port 0 pins to be skippe d by the crossbar decoder. port pins used for analog, special functions or gpio should be skipped by the crossbar. 0: corresponding p0.n pin is not skipped by the crossbar. 1: corresponding p0.n pin is skipped by the crossbar. www.datasheet.in
rev. 1.0 227 c8051f99x-c8051f98x sfr page= 0x0; sfr address = 0xf1 sfr page = 0x0; sfr address = 0xa4 sfr definition 21.10. p0mdin: port0 input mode bit 7 6 5 4 3 2 1 0 name p0mdin[7:0] type r/w reset 11111111 bit name function 7:0 p0mdin[7:0] analog configuration bits for p0.7?p0.0 (respectively). port pins configured for analog mode have their weak pullup, and digital receiver disabled. the digital driver is not explicitly disabled. 0: corresponding p0.n pin is configured for analog mode. 1: corresponding p0.n pin is not configured for analog mode. sfr definition 21.11. p0mdout: port0 output mode bit 7 6 5 4 3 2 1 0 name p0mdout[7:0] type r/w reset 00000000 bit name function 7:0 p0mdout[7:0] output configuration bits for p0.7?p0.0 (respectively). these bits control the digital driver even when the corresponding bit in register p0mdin is logic 0. 0: corresponding p0.n output is open-drain. 1: corresponding p0.n output is push-pull. www.datasheet.in
c8051f99x-c8051f98x 228 rev. 1.0 sfr page = 0xf; sfr address = 0xa4 sfr definition 21.12. p0drv: port0 drive strength bit 7 6 5 4 3 2 1 0 name p0drv[7:0] type r/w reset 00000000 bit name function 7:0 p0drv[7:0] drive strength configuration bits for p0.7?p0.0 (respectively). configures digital i/o port cells to high or low output drive strength. 0: corresponding p0.n output has low output drive strength. 1: corresponding p0.n output has high output drive strength. www.datasheet.in
rev. 1.0 229 c8051f99x-c8051f98x sfr page = all; sfr address = 0x90; bit-addressable sfr page = 0x0; sfr address = 0xd5 sfr definition 21.13. p1: port1 bit 7 6 5 4 3 2 1 0 name p1[7:0] type r/w reset 11111111 bit name description write read 7:0 p1[6:0] port 1 data. sets the port latch logic value or reads the port pin logic state in port cells con - figured for digital i/o. 0: set output latch to logic low. 1: set output latch to logic high. 0: p1.n port pin is logic low. 1: p1.n port pin is logic high. sfr definition 21.14. p1skip: port1 skip bit 7 6 5 4 3 2 1 0 name p1skip[7:0] type r/w reset 00000000 bit name function 7:0 p1skip[6:0] port 1 crossbar skip enable bits. these bits select port 1 pins to be skippe d by the crossbar decoder. port pins used for analog, special functions or gpio should be skipped by the crossbar. 0: corresponding p1.n pin is not skipped by the crossbar. 1: corresponding p1.n pin is skipped by the crossbar. www.datasheet.in
c8051f99x-c8051f98x 230 rev. 1.0 sfr page = 0x0; sfr address = 0xf2 sfr page = 0x0; sfr address = 0xa5 sfr definition 21.15. p1mdin: port1 input mode bit 7 6 5 4 3 2 1 0 name p1mdin[7:0] type r/w reset 11111111 bit name function 7:0 p1mdin[7:0] analog configuration bits for p1.7?p1.0 (respectively). port pins configured for analog mode have their weak pullup and digital receiver disabled. the digital driver is not explicitly disabled. 0: corresponding p1.n pin is configured for analog mode. 1: corresponding p1.n pin is not configured for analog mode. sfr definition 21.16. p1mdout: port1 output mode bit 7 6 5 4 3 2 1 0 name p1mdout[7:0] type r/w reset 00000000 bit name function 7:0 p1mdout[7:0] output configuration bits for p1.7?p1.0 (respectively). these bits control the digital driver even when the corresponding bit in register p1mdin is logic 0. 0: corresponding p1.n output is open-drain. 1: corresponding p1.n output is push-pull. www.datasheet.in
rev. 1.0 231 c8051f99x-c8051f98x sfr page = 0xf; sfr address = 0xa5 sfr page = all; sfr address = 0xa0; bit-addressable sfr definition 21.17. p1drv: port1 drive strength bit 7 6 5 4 3 2 1 0 name p1drv[7:0] type r/w reset 00000000 bit name function 7:0 p1drv[7:0] drive strength configuration bits for p1.7?p1.0 (respectively). configures digital i/o port cells to high or low output drive strength. 0: corresponding p1.n output has low output drive strength. 1: corresponding p1.n output has high output drive strength. sfr definition 21.18. p2: port2 bit 7 6 5 4 3 2 1 0 name p2 type r/w reset 10000000 bit name description read write 7 p2 port 2 data. sets the port latch logic value or reads the port pin logic state in port cells con - figured for digital i/o. 0: set output latch to logic low. 1: set output latch to logic high. 0: p2.7 port pin is logic low. 1: p2.7 port pin is logic high. 6:0 unused read = 0000000b; write = don?t care. www.datasheet.in
c8051f99x-c8051f98x 232 rev. 1.0 sfr page = 0x0; sfr address = 0xa6 sfr page = 0x0f; sfr address = 0xa6 sfr definition 21.19. p2mdout: port2 output mode bit 7 6 5 4 3 2 1 0 name p2mdout type r/w reset 00000000 bit name function 7 p2mdout output configuration bits for p2.7. these bits control the digital driver. 0: p2.7 output is open-drain. 1: p2.7 output is push-pull. 6:0 unused read = 0000000b; write = don?t care. sfr definition 21.20. p2drv: port2 drive strength bit 7 6 5 4 3 2 1 0 name p2drv type r/w reset 00000000 bit name function 7 p2drv drive strength configuration bits for p2.7. configures digital i/o port cells to high or low output drive strength. 0: p2.7 output has low output drive strength. 1: p2.7 output has high output drive strength. 6:0 unused read = 0000000b; write = don?t care. www.datasheet.in
rev. 1.0 233 c8051f99x-c8051f98x 22. smbus the smbus i/o interface is a two-wire, bi-directional serial bus. the smbus is compatible with the system management bus specification, version 1.1, and compatible with the i 2 c serial bus. reads and writes to the interface by the system contro ller are byte oriented with the smbu s interface autonom ously controlling the serial transfer of the data. data can be transferre d at up to 1/20th of the system clock as a master or slave (this can be faster than allowed by the smbus specification, depending on the system clock used). a method of extending the clock-low duration is ava ilable to accommodate devices with different speed capabilities on the same bus. the smbus interface may operate as a master and/or slave, and may function on a bus with multiple mas - ters. the smbus provides control of sda (serial data), scl (serial clock) generation and synchronization, arbitration logic, and start/stop control and genera tion. the smbus peripheral can be fully driven by software (i.e. software accepts/re jects slave addresses, and generate s acks), or hardware slave address recognition and automatic ack gener ation can be enabled to minimize software overhead. a block dia - gram of the smbus peripheral and the associated sfrs is shown in figure 22.1 . figure 22.1. smbus block diagram data path control smbus control logic c r o s s b a r scl filter n sda control scl control interrupt request port i/o smb0cn s t a a c k r q a r b l o s t a c k s i t x m o d e m a s t e r s t o 01 00 10 11 t0 overflow t1 overflow tmr2h overflow tmr2l overflow smb0cf e n s m b i n h b u s y e x t h o l d s m b t o e s m b f t e s m b c s 1 s m b c s 0 0 1 2 3 4 5 6 7 smb0dat sda filter n smb0adr s l v 4 s l v 2 s l v 1 s l v 0 g c s l v 5 s l v 6 s l v 3 smb0adm s l v m 4 s l v m 2 s l v m 1 s l v m 0 e h a c k s l v m 5 s l v m 6 s l v m 3 arbitration scl synchronization hardware ack generation scl generation (master mode) sda control hardware slave address recognition irq generation www.datasheet.in
c8051f99x-c8051f98x 234 rev. 1.0 22.1. supporting documents it is assumed the reader is fam iliar with or has access to th e following supporting documents: ? the i 2 c-bus and how to use it (including s pecifications), philips semiconductor. ? the i 2 c-bus specification?version 2.0, philips semiconductor. ? system management bus specification? version 1.1, sbs implementers forum. 22.2. smbus configuration figure 22.2 shows a typical smbus configuration. the smbu s specification allows any recessive voltage between 3.0 v and 5.0 v; different devices on the bus may operate at different voltage levels. note: the port pins on c8051f99x-c8051f98x devices are not 5 v tolerant, therefore, the device may only be used in smbus networks where the supply voltage does not exceed v dd . the bi-directional scl (serial clock) and sda (seria l data) lines must be conn ected to a positive power supply voltage through a pullup resistor or similar circ uit. every device connected to the bus must have an open-drain or open-collector output for both the scl and sda lines, so that both are pulled high (recessive state) when the bus is free. the maximum number of devices on the bus is limit ed only by the requirement that the rise and fall times on the bus not exceed 300 ns and 1000 ns, respectively. figure 22.2. typical smbus configuration vdd = 3 v master device slave device 1 slave device 2 vdd = 3 v vdd = 3 v vdd = 3 v sda scl www.datasheet.in
rev. 1.0 235 c8051f99x-c8051f98x 22.3. smbus operation two types of data transfers are possible: data transfers from a master transmitter to an addressed slave receiver (write), and data transfers from an addres sed slave transmitter to a master receiver (read). the master device initiates both types of data transfer s and provides the serial clock pulses on scl. the smbus interface may operate as a master or a slave, and multiple master devices on the same bus are supported. if two or more masters attempt to initiate a data transfer simultaneously, an arbitration scheme is employed with a single master always winning the arbitr ation. note that it is not necessary to specify one device as the master in a system ; any device who transmits a star t and a slave address becomes the master for the duration of that transfer. a typical smbus transaction consists of a start cond ition followed by an address byte (bits7?1: 7-bit slave address; bit0: r/w direction bit), one or more bytes of data, and a stop condition. bytes that are received (by a master or slave) are acknowledg ed (ack) with a low sda during a high scl (see figure 22.3 ). if the receiving device does not ack, the transmitting devi ce will read a nack (not acknowl - edge), which is a high sda during a high scl. the direction bit (r/w) occupies the least-significant bit position of the address byte. the direction bit is set to logic 1 to indicate a "read" operation and cleared to logic 0 to indicate a "write" operation. all transactions are initiated by a master, with one or more addressed slave devices as the target. the master generates the start condition and then transmit s the slave address and direction bit. if the trans - action is a write operation from the master to the slave, the master tr ansmits the data a byte at a time waiting for an ack from the slave at the end of each byte. for read operations , the slave transmits the data waiting for an ack from the master at the end of each byte. at the end of the data transfer, the master generates a stop condition to terminate the transaction and free the bus. figure 22.3 illustrates a typical smbus transaction. figure 22.3. smbus transaction 22.3.1. transmitter vs. receiver on the smbus communications interface, a device is the ?transmitter? when it is sending an address or data byte to another device on the bus. a device is a ?receiver? when an ad dress or data byte is being sent to it from another device on the bus. the transmitter controls the sda line during the address or data byte. after each byte of address or data information is sent by the transmitter, the receiver sends an ack or nack bit during the ack phase of the transfer, dur ing which time the receiver controls the sda line. 22.3.2. arbitration a master may start a transfer only if the bus is free. th e bus is free after a stop condition or after the scl and sda lines remain high for a specified time (see section ?22.3.5. scl high (smbus free) timeout? on page 236 ). in the event that two or more devices attempt to begin a transfer at the same time, an arbitra - tion scheme is employed to force one master to give up the bus. the master devices continue transmitting until one attempts a high while the other transmits a low. since the bus is open-drain, the bus will be pulled low. the master attempting th e high will detect a low sda and lo se the arbitration. the winning sla6 sda sla5-0 r/w d7 d6-0 scl slave address + r/w data byte start ack nack stop www.datasheet.in
c8051f99x-c8051f98x 236 rev. 1.0 master continues its transmission without interruption; the losing master becomes a slave and receives the rest of the transfer if addressed. this arbitration scheme is non-destru ctive: one device always wins, and no data is lost. 22.3.3. clock low extension smbus provides a clock synchron ization mechanism, similar to i 2 c, which allows devices with different speed capabilities to coexist on the bus. a clock-low extension is used du ring a transfer in order to allow slower slave devices to communica te with faster masters. the slave may temporarily hold the scl line low to extend the clock low period, effectively decreasing the serial clock frequency. 22.3.4. scl low timeout if the scl line is held low by a slave device on the bus , no further communication is possible. furthermore, the master cannot force the scl line high to correct th e error condition. to solve this problem, the smbus protocol specifies that devices participating in a tran sfer must detect any clock cy cle held low longer than 25 ms as a ?timeout? condition. devices that have det ected the timeout condition must reset the communi - cation no later than 10 ms after detecting the timeout condition. when the smbtoe bit in smb0cf is set, timer 3 is used to detect scl low timeouts. timer 3 is forced to reload when scl is high, and allowed to count when scl is low. with timer 3 enabled and configured to overflow after 25 ms (and smbtoe set), the timer 3 interrupt service routine can be used to reset (disable and re-enable) the smbus in the event of an scl low timeout. 22.3.5. scl high (smbus free) timeout the smbus specification stipulates that if the scl and sda lines remain high for more that 50 s, the bus is designated as free. when the sm bfte bit in smb0cf is set, the bu s will be considered free if scl and sda remain high for more than 10 smbus clock source periods (as defined by the timer configured for the smbus clock source). if the smbus is waiting to generate a master start, the start will be generated following this timeout. note that a clock source is required for free timeout detection, even in a slave-only implementation. www.datasheet.in
rev. 1.0 237 c8051f99x-c8051f98x 22.4. using the smbus the smbus can operate in both master and slave modes. the interface provides timing and shifting con - trol for serial transfers; higher level protocol is dete rmined by user software. the smbus interface provides the following application-independent features: ? byte-wise serial data transfers ? clock signal generation on scl (master mode only) and sda data synchronization ? timeout/bus error recognition, as defined by the smb0cf configuration register ? start/stop timing, detection, and generation ? bus arbitration ? interrupt generation ? status information ? optional hardware recognition of slave address and automatic acknowledgement of address/data smbus interrupts are generated for each data byte or slave address that is transferred. when hardware acknowledgement is disabled, the point at which the interrupt is generated depends on whether the hard - ware is acting as a data transmitter or receiver. when a transmitter (i.e. sending address/data, receiving an ack), this interrupt is generated after the ack cycle so that software may read the received ack value; when receiving data (i.e., receiving address/data, send ing an ack), this interrupt is generated before the ack cycle so that software may def ine the outgoing ack value. if har dware acknowledgement is enabled, these interrupts are always generated after the ack cycle. see section 22.5 for more details on transmis - sion sequences. interrupts are also generated to indicate the beginning of a transfer when a master (start generated), or the end of a transfer when a slave (stop detected) . software should read the smb0cn (smbus control register) to find the cause of the smbus inte rrupt. the smb0cn register is described in section 22.4.2 ; ta b l e 22.5 provides a quick smb0cn decoding reference. www.datasheet.in
c8051f99x-c8051f98x 238 rev. 1.0 22.4.1. smbus configuration register the smbus configuration register (s mb0cf) is used to enable the smbus master and/or slave modes, select the smbus clock source, and select the smbus timing and timeout options . when the ensmb bit is set, the smbus is enabled for all master and slave events. slave events may be disabled by setting the inh bit. with slave events inhibited, the smbus in terface will still monitor the scl and sda pins; however, the interface will nack all received addresses and will not generate any slave inte rrupts. when the inh bit is set, all slave events will be inhibited following the ne xt start (interrupts will cont inue for the duration of the current transfer). the smbcs1?0 bits select the smbus clock source, which is used only when operating as a master or when the free timeout detection is enabled. when op erating as a master, overflows from the selected source determine the absolute minimum scl low and high times as defined in equation 22.1 . note that the selected clock source may be shared by other peripherals so long as the timer is left running at all times. for example, timer 1 overflows may generate the smbus and uart baud rates simultaneously. timer configuration is covered in section ?25. timers? on page 276 . equation 22.1. minimum scl high and low times the selected clock source should be configured to establish the minimum scl high and low times as per equation 22.1 . when the interface is operating as a master (and scl is not driven or extended by any other devices on the bus), the typica l smbus bit rate is approximated by equation 22.2 . equation 22.2. typical smbus bit rate figure 22.4 shows the typical scl generation described by equation 22.2 . notice that t high is typically twice as large as t low . the actual scl output may vary due to other devices on the bus (scl may be extended low by slower slave devices, or driven low by contending master devices). the bit rate when operating as a master will never exce ed the limits defined by equation equation 22.1 . figure 22.4. typical smbus scl generation table 22.1. smbus clock source selection smbcs1 smbcs0 smbus clock source 0 0 timer 0 overflow 0 1 timer 1 overflow 1 0 timer 2 high byte overflow 1 1 timer 2 low byte overflow t highmin t lowmin 1 f clocksourceoverflow ---------------- ------------------ ----------- - == bitrate f clocksourceoverflow 3 --------------- ----------------- ------------- - = scl timer source overflows scl high timeout t low t high www.datasheet.in
rev. 1.0 239 c8051f99x-c8051f98x setting the exthold bit extends the minimum setup and hold times for the sda line. the minimum sda setup time defines the absolute mini mum time that sda is stable before scl transitions from low-to-high. the minimum sda hold time defines the absolute minimum time that the current sda value remains stable after scl transitions from high-to-low. exthold should be set so that the minimum setup and hold times meet the smbus specification requirements of 250 ns and 300 ns, respectively. ta b l e 22.2 shows the min - imum setup and hold times for the two exthold settings. setup and hold time extensions are typically necessary when sysclk is above 10 mhz. with the smbtoe bit set, timer 3 should be configured to overflow after 25 ms in order to detect scl low timeouts (see section ?22.3.4. scl low timeout? on page 236 ). the smbus interface will force timer 3 to reload while scl is high, and allow timer 3 to count when scl is low. the timer 3 interrupt service routine should be used to reset smbus communication by disabling and re-enabling the smbus. smbus free timeout detection can be enabled by setting the smbfte bit. when this bit is set, the bus will be considered free if sda and scl remain high for more than 10 smbus clock source periods (see figure 22.4 ). table 22.2. minimum sda setup and hold times exthold minimum sda setup time minimum sda hold time 0 t low ? 4 system clocks or 1 system clock + s/w delay* 3 system clocks 1 11 system clocks 12 system clocks *note: setup time for ack bit transmissions and the msb of all data transfers. when using software acknowledgement, the s/w delay occurs between the time smb0dat or ack is written and when si is cleared. note that if si is cleared in the same write that defines the outgoing ack value, s/w delay is zero. www.datasheet.in
c8051f99x-c8051f98x 240 rev. 1.0 sfr page = 0x0; sfr address = 0xc1 sfr definition 22.1. smb0cf: smbus clock/configuration bit 7 6 5 4 3 2 1 0 name ensmb inh busy exthold smbtoe smbfte smbcs[1:0] type r/w r/w r r/w r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 ensmb smbus enable. this bit enables the smbus interface when set to 1. when enabled, the interface constantly monitors the sda and scl pins. 6 inh smbus slave inhibit. when this bit is set to logic 1, the smbu s does not generate an interrupt when slave events occur. this effectively removes th e smbus slave from the bus. master mode interrupts are not affected. 5 busy smbus busy indicator. this bit is set to logic 1 by hardware when a transfer is in progress. it is cleared to logic 0 when a stop or free-timeout is sensed. 4 exthold smbus setup and hold time extension enable. this bit controls the sda setup and hold times according to ta b l e 22.2 . 0: sda extended setup and hold times disabled. 1: sda extended setup and hold times enabled. 3 smbtoe smbus scl timeout detection enable. this bit enables scl low timeout detection. if set to logic 1, the smbus forces timer 3 to reload while scl is high and allows timer 3 to count when scl goes low. if timer 3 is configured to split mode, only the high byte of the timer is held in reload while scl is high. timer 3 should be programmed to generate interrupts at 25 ms, and the timer 3 interrupt service routine should reset smbus communication. 2 smbfte smbus free timeout detection enable. when this bit is set to logic 1, the bus will be considered free if scl and sda remain high for more than 10 smbus clock source periods. 1 : 0 smbcs[1:0] smbus clock source selection. these two bits select the smbus clock sour ce, which is used to generate the smbus bit rate. the selected device should be configured according to equation 22.1 . 00: timer 0 overflow 01: timer 1 overflow 10:timer 2 high byte overflow 11: timer 2 low byte overflow www.datasheet.in
rev. 1.0 241 c8051f99x-c8051f98x 22.4.2. smb0cn control register smb0cn is used to control the interface and to provide status information (see sfr definition 22.2 ). the higher four bits of smb0cn (master, txmode, sta, and sto) form a status vector that can be used to jump to service routines. master indicates whether a device is the master or slave during the current transfer. txmode indicates whether the device is tr ansmitting or receiving data for the current byte. sta and sto indicate that a start and/or stop ha s been detected or generated since the last smbus interrupt. sta and sto are also used to generate start and stop conditions when operating as a mas - ter. writing a 1 to sta will cause the smbus interface to enter master mode and generate a start when the bus becomes free (sta is not cleared by hardwar e after the start is generated). writing a 1 to sto while in master mode will cause the interface to generate a stop and end the current transfer after the next ack cycle. if sto and sta are both set (while in master mode), a stop followed by a start will be generated. the arblost bit indicates that the interface has lost an arbitration. this may occur anytime the interface is transmitting (master or slave). a lost arbitratio n while operating as a slave indicates a bus error condi - tion. arblost is cleared by hardware each time si is cleared. the si bit (smbus interrupt flag) is set at the beginnin g and end of each transfer, after each byte frame, or when an arbitration is lost; see ta b l e 22.3 for more details. important note about the si bit: the smbus interface is stalled while si is set; thus scl is held low, and the bus is stalled until software clears si. 22.4.2.1.software ack generation when the ehack bit in register smb0 adm is cleared to 0, the firmware on the device must detect incom - ing slave addresses and ack or nack the slave addres s and incoming data bytes. as a receiver, writing the ack bit defines the outgoing ack value; as a tr ansmitter, reading the ack bit indicates the value received during the last ack cycle. ackrq is set each ti me a byte is received, indi cating that an outgoing ack value is needed. when ackrq is set, software should write the desired outgoing value to the ack bit before clearing si. a nack will be g enerated if software does not writ e the ack bit before clearing si. sda will reflect the defined ack value immediately following a write to the ack bit; however scl will remain low until si is cleared. if a received slave address is not acknow ledged, further slave events will be ignored until the next start is detected. 22.4.2.2.hardwar e ack generation when the ehack bit in register smb0adm is set to 1, automatic slave address recognition and ack gen - eration is enabled. more detail about automatic slave address recognition can be found in section 22.4.3 . as a receiver, the value currently specified by the ac k bit will be automatically sent on the bus during the ack cycle of an incoming data byte. as a transmitter, reading the ack bit indicates the value received on the last ack cycle. the ackrq bit is not used when hardware ack generation is enabled. if a received slave address is nacked by hardware, further sl ave events will be ignored un til the next start is detected, and no interrupt will be generated. ta b l e 22.3 lists all sources for hardware changes to the smb0cn bits. refer to ta b l e 22.5 for smbus sta - tus decoding using the smb0cn register. www.datasheet.in
c8051f99x-c8051f98x 242 rev. 1.0 sfr page = 0x0; sfr addres s = 0xc0; bit-addressable sfr definition 22.2. smb0cn: smbus control bit 7 6 5 4 3 2 1 0 name master txmode sta sto ackrq arblost ack si type rrr/wr/wrrr/wr/w reset 00000000 bit name description read write 7 master smbus master/slave indicator. this read-only bit indicates when the smbus is operating as a master. 0: smbus operating in slave mode. 1: smbus operating in master mode. n/a 6 txmode smbus transmit mode indicator. this read-only bit indicates when the smbus is operating as a transmitter. 0: smbus in receiver mode. 1: smbus in transmitter mode. n/a 5 sta smbus start flag. 0: no start or repeated start detected. 1: start or repeated start detected. 0: no start generated. 1: when configured as a master, initiates a start or repeated start. 4 sto smbus stop flag. 0: no stop condition detected. 1: stop condition detected (if in slave mode) or pend - ing (if in master mode). 0: no stop condition is transmitted. 1: when configured as a master, causes a stop condition to be transmit - ted after the next ack cycle. cleared by hardware. 3 ackrq smbus acknowledge request. 0: no ack requested 1: ack requested n/a 2 arblost smbus arbitration lost indicator. 0: no arbitration error. 1: arbitration lost n/a 1 ack smbus acknowledge. 0: nack received. 1: ack received. 0: send nack 1: send ack 0 si smbus interrupt flag. this bit is set by hardware under the conditions listed in table 15.3. si must be cleared by software. while si is set, scl is held low and the smbus is stalled. 0: no interrupt pending 1: interrupt pending 0: clear interrupt, and initi - ate next state machine event. 1: force interrupt. www.datasheet.in
rev. 1.0 243 c8051f99x-c8051f98x table 22.3. sources for hardware changes to smb0cn bit set by hardware when: cleared by hardware when: master ? a start is generated. ? a stop is generated. ? arbitration is lost. txmode ? start is generated. ? smb0dat is written before the start of an smbus frame. ? a start is detected. ? arbitration is lost. ? smb0dat is not written before the start of an smbus frame. sta ? a start followed by an address byte is received. ? must be cleared by software. sto ? a stop is detected while addressed as a slave. ? arbitration is lost due to a detected stop. ? a pending stop is generated. ackrq ? a byte has been received and an ack response value is needed (only when hardware ack is not enabled). ? after each ack cycle. arblost ? a repeated start is detected as a master when sta is low (unwanted repeated start). ? scl is sensed low wh ile attempting to generate a stop or repeated start condition. ? sda is sensed low while transmitting a 1 (excluding ack bits). ? each time si is cleared. ack ? the incoming ack value is low ? (acknowledge). ? the incoming ack value is high (not acknowledge). si ? a start has been generated. ? lost arbitration. ? a byte has been transmitted and an ack/nack received. ? a byte has been received. ? a start or repeated start followed by a slave address + r/w has been received. ? a stop has been received. ? must be cleared by software. www.datasheet.in
c8051f99x-c8051f98x 244 rev. 1.0 22.4.3. hardware slave address recognition the smbus hardware has the capability to automatically recognize incoming slav e addresses and send an ack without software intervention. automatic slave address recognition is enabled by setting the ehack bit in register smb0adm to 1. this will enable both automatic slave address recognition and automatic hardware ack generation for received bytes (as a mast er or slave). more detail on automatic hardware ack generation can be found in section 22.4.2.2 . the registers used to define which address(es) ar e recognized by the hardware are the smbus slave address register ( sfr definition 22.3 ) and the smbus slave address mask register ( sfr definition 22.4 ). a single address or range of addresses (including the general call address 0x00) can be specified using these two registers. the most-significant seven bits of the two registers are used to define which addresses will be acked. a 1 in bit pos itions of the slave address mask slvm[6:0] enable a comparison between the received slave address and the hardware?s sl ave address slv[6:0] for those bits. a 0 in a bit of the slave address mask means that bit will be treated as a ?don?t care ? for comparison purposes. in this case, either a 1 or a 0 value are acceptable on the in coming slave address. additionally, if the gc bit in register smb0adr is set to 1, hardware w ill recognize the genera l call address (0x00). ta b l e 22.4 shows some example parameter settings and the slave ad dresses that will be recogni zed by hardware under those conditions. table 22.4. hardware address recognition examples (ehack = 1) hardware slave address slv[6:0] slave address mask slvm[6:0] gc bit slave addresses recognized by hardware 0x34 0x7f 0 0x34 0x34 0x7f 1 0x34, 0x00 (general call) 0x34 0x7e 0 0x34, 0x35 0x34 0x7e 1 0x34, 0x35, 0x00 (general call) 0x70 0x73 0 0x70, 0x74, 0x78, 0x7c www.datasheet.in
rev. 1.0 245 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xf4 sfr page = 0x0; sfr address = 0xf5 sfr definition 22.3. smb0adr: smbus slave address bit 7 6 5 4 3 2 1 0 name slv[6:0] gc type r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 : 1 slv[6:0] smbus hardware slave address. defines the smbus slave address(es) for automatic hardware acknowledgement. only address bits which have a 1 in the corresponding bit position in slvm[6:0] are checked against the incoming address. this allows multiple addresses to be recognized. 0 gc general call address enable. when hardware address reco gnition is enabled (ehack = 1), this bit will deter - mine whether the general call address (0 x00) is also recognized by hardware. 0: general call ad dress is ignored. 1: general call address is recognized. sfr definition 22.4. smb0adm: smbus slave address mask bit 7 6 5 4 3 2 1 0 name slvm[6:0] ehack type r/w r/w reset 1111111 0 bit name function 7 : 1 slvm[6:0] smbus slave address mask. defines which bits of register smb0adr are compared with an incoming address byte, and which bits are ignored. any bit set to 1 in slvm[6:0] enables compari - sons with the corresponding bit in slv[6:0]. bits set to 0 are ignored (can be either 0 or 1 in the incoming address). 0 ehack hardware acknowledge enable. enables hardware acknowledgement of slave address and received data bytes. 0: firmware must manually acknowledge all incoming address and data bytes. 1: automatic slave address recognition and hardware acknowledge is enabled. www.datasheet.in
c8051f99x-c8051f98x 246 rev. 1.0 22.4.4. data register the smbus data register smb0dat holds a byte of serial data to be transmitted or one that has just been received. software may safely read or write to the data register when the si flag is set. software should not attempt to access the smb0dat register when the smbus is enabled and the si flag is cleared to logic 0, as the interface may be in the process of shifting a byte of data into or out of the register. data in smb0dat is always shifted ou t msb first. after a byte has been received, the first bit of received data is located at the msb of smb0dat. while data is being shifted out, data on the bus is simultaneously being shifted in. smb0dat always contains the last data byte present on the bus. in the event of lost arbi - tration, the transition from master transmitter to slave receiver is made with the correct data or address in smb0dat. sfr page = 0x0; sfr address = 0xc2 sfr definition 22.5. smb0dat: smbus data bit 7 6 5 4 3 2 1 0 name smb0dat[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7 : 0 smb0dat[7:0] smbus data. the smb0dat register contains a byte of data to be transmitted on the smbus serial interface or a byte that has just b een received on the smbus serial interface. the cpu can read from or write to this regi ster whenever the si serial interrupt flag (smb0cn.0) is set to logic 1. the serial data in the register remains stable as long as the si flag is set. when the si flag is not set, the system may be in the process of shifting data in/out and the cpu shou ld not attempt to access this register. www.datasheet.in
rev. 1.0 247 c8051f99x-c8051f98x 22.5. smbus transfer modes the smbus interface may be configured to operate as master and/or slave. at any particular time, it will be operating in one of the following four modes: master transmitter, master receiver, slave transmitter, or slave receiver. the smbus interface enters master mo de any time a start is generated, and remains in master mode until it loses an arbitration or generates a stop. an smbus interrupt is generated at the end of all smbus byte frames. note that the position of the ack interrupt when operating as a receiver depends on whether hardware ack generation is enabled . as a receiver, the inte rrupt for an ack occurs before the ack with hardware ack generation disabled, and after the ack when hardware ack genera - tion is enabled. as a transmitter, interrupts occur after the ack, regardless of whether hardware ack gen - eration is enabled or not. 22.5.1. write sequence (master) during a write sequence, an smbus mast er writes data to a slave device. the master in this transfer will be a transmitter during the address byte, and a transmitter during all data bytes. the smbus interface gener - ates the start condition and transmits the first byte containing the address of the target slave and the data direction bit. in this case th e data direction bit (r/w) will be logic 0 (write). the master then trans - mits one or more bytes of serial data. after each byte is transmitted, an acknowledge bit is generated by the slave. the transfer is ended wh en the sto bit is set and a stop is generated. note that the interface will switch to master receiver mode if smb0dat is not written followin g a master transm itter interrupt. figure 22.5 shows a typical master write sequence. two tr ansmit data bytes are shown, though any num - ber of bytes may be transmitted. notice that all of the ?data byte transferred? interrupts occur after the ack cycle in this mode, regardless of whether hardware ack generation is enabled. figure 22.5. typical master write sequence a a a s w p data byte data byte sla s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1) www.datasheet.in
c8051f99x-c8051f98x 248 rev. 1.0 22.5.2. read sequence (master) during a read sequence, an smbus ma ster reads data from a slave devic e. the master in this transfer will be a transmitter during the address byte, and a receiv er during all data bytes. the smbus interface gener - ates the start condition and transmits the first byte containing the address of the target slave and the data direction bit. in this case t he data direction bit (r/w) will be logic 1 (read). serial data is then received from the slave on sda while the smbus outputs the serial clock. the slave transmits one or more bytes of serial data. if hardware ack generation is disabled, the ackrq is set to 1 and an interrupt is generated after each received byte. software must writ e the ack bit at that time to ack or nack the received byte. with hardware ack generation enab led, the smbus hardware will autom atically generate the ack/nack, and then post the interrupt. it is important to note that the appropriate ack or nack value should be set up by the software prior to receiving the byte when hardware ack generation is enabled. writing a 1 to the ack bit generates an ack; writing a 0 generates a nack. software should write a 0 to the ack bit for the last data transfer, to transmit a nack. the interface exits master receiver mode after the sto bit is set and a stop is generated. the interface will switch to mast er transmitter mode if smb0dat is written while an active master receiver. figure 22.6 shows a typical master read sequence. two received data bytes are shown, though any number of bytes may be received. notice that the ?data byte transferred? interrupts occur at different places in the sequence, depending on whether hardware ack generation is enabled. the interrupt occurs before the ack with hardware ack generation disabled, and after the ack when hardware ack generation is enabled. figure 22.6. typical master read sequence data byte data byte a n a s r p sla s = start p = stop a = ack n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1) www.datasheet.in
rev. 1.0 249 c8051f99x-c8051f98x 22.5.3. write sequence (slave) during a write sequence, an smbus ma ster writes data to a slave device. the slave in this transfer will be a receiver during the address byte, and a receiver during all data bytes. when slave events are enabled (inh = 0), the interface enters slave receiver mode when a start followed by a slave address and direc - tion bit (write in this case) is received. if hardware ack generation is disabled, upon entering slave receiver mode, an interrupt is generated and the ac krq bit is set. the software must respond to the received slave address with an ack, or ignore the received slave address with a nack. if hardware ack generation is enabled, th e hardware will apply the ac k for a slave address which matches the criteria set up by smb0adr and smb0adm. the inte rrupt will occur after the ack cycle. if the received slave address is ignore d (by software or hardware), slav e interrupts will be in hibited until the next start is detected. if the received slave address is acknowledged, zero or more data bytes are received. if hardware ack generation is disabled, the ackrq is set to 1 and an interrupt is generated after each received byte. software must writ e the ack bit at that time to ack or nack the received byte. with hardware ack generation enab led, the smbus hardware will autom atically generate the ack/nack, and then post the interrupt. it is important to note that the appropriate ack or nack value should be set up by the software prior to receiving the byte when hardware ack generation is enabled. the interface exits slave re ceiver mode after receiving a stop. note that the interface will switch to slave transmitter mode if smb0 dat is written while an active slave receiver. figure 22.7 shows a typical slave write sequence. two received data bytes are shown, though any number of bytes may be received. notice that the ?data byte transferred? interrupts occur at different places in the sequence, depending on whether hardware ack generation is enabled. the interrupt occurs before the ack with hardware ack generation disabled, and after the ack when hardware ack generation is enabled. figure 22.7. typical slave write sequence p w sla s data byte data byte a a a s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1) www.datasheet.in
c8051f99x-c8051f98x 250 rev. 1.0 22.5.4. read sequence (slave) during a read sequence, an smbus ma ster reads data from a slave device. the slave in this transfer will be a receiver during the address byte, and a transm itter during all data bytes. when slave events are enabled (inh = 0), the interface enters slave receiver mode (to receive the slave address) when a start followed by a slave address and direction bit (read in this case) is received. if hardware ack generation is disabled, upon entering slave receiver mode, an interrupt is generated and the ackrq bit is set. the software must respond to the received slave address with an ack, or ignore the received slave address with a nack. if hardware ack generat ion is enabled, the hardware will apply the ack for a slave address which matches the criteria set up by smb0adr and smb0adm. the interrupt will occur after the ack cycle. if the received slave address is ignore d (by software or hardware), slav e interrupts will be in hibited until the next start is detected. if the received slave address is acknowledged, zero or more data bytes are trans - mitted. if the received slave address is acknowledged, data should be written to smb0dat to be transmit - ted. the interface enters slave transmitter mode, and tr ansmits one or more bytes of data. after each byte is transmitted, the master sends an acknowledge bit; if the acknowledge bit is an ack, smb0dat should be written with the next data byte. if the acknowle dge bit is a nack, smb0dat should not be written to before si is cleared (note: an error condition may be generated if smb0dat is wr itten following a received nack while in slave transmitter mo de). the interface exits slave transmitter mode after receiving a stop. note that the interface will switch to slav e receiver mode if smb0dat is not written following a slave transmitter interrupt. figure 22.8 shows a typical slave read sequence. two transmitted data bytes are shown, though any number of byte s may be transmitted. notice that all of the ?data byte transferred? interrupts occur after the ack cycle in this mode, regardless of whether hardware ack generation is enabled. figure 22.8. typical slave read sequence 22.6. smbus status decoding the current smbus status can be easily decoded usin g the smb0cn register. the appropriate actions to take in response to an smbus event depend on whether hardware slave address recognition and ack generation is enabled or disabled. ta b l e 22.5 describes the typical actions when hardware slave address recognition and ack generation is disabled. ta b l e 22.6 describes the typical actions when hardware slave address recognition and ack generation is enabled. in the tables, status vector refers to the four upper bits of smb0cn: master, tx mode, sta, and sto. the shown response options are only the typ - ical responses; application-specific procedures are allo wed as long as they conform to the smbus specifi - cation. highlighted responses are allowed by hardwar e but do not conform to the smbus specification. p r sla s data byte data byte a n a s = start p = stop n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1) www.datasheet.in
rev. 1.0 251 c8051f99x-c8051f98x table 22.5. smbus status decoding with hardware ack generation disabled (ehack = 0) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack master transmitter 1110 0 0 x a master start was gener - ated. load slave address + r/w into smb0dat. 00x1100 1100 000 a master data or address byte was transmitted; nack received. set sta to restart transfer. 10x1110 abort transfer. 01x ? 001 a master data or address byte was transmitted; ack received. load next data byte into smb0dat. 00x1100 end transfer with stop. 01x ? end transfer with stop and start another transfer. 11x ? send repeated start. 10x1110 switch to master receiver mode (clear si without writing new data to smb0dat). 0 0 x 1000 master receiver 1000 1 0 x a master data byte was received; ack requested. acknowledge received byte; read smb0dat. 0 0 1 1000 send nack to indi cate last byte, and send stop. 010 ? send nack to indi cate last byte, and send stop followed by start. 1101110 send ack followed by repeated start. 1011110 send nack to indi cate last byte, and send repeated start. 1001110 send ack and switch to master transmitter mode (write to smb0dat before clearing si). 0 0 1 1100 send nack and switch to mas - ter transmitter mode (write to smb0dat before clearing si). 0 0 0 1100 www.datasheet.in
c8051f99x-c8051f98x 252 rev. 1.0 slave transmitter 0100 000 a slave byte was transmitted; nack received. no action required (expecting stop condition). 0 0 x 0001 001 a slave byte was transmitted; ack received. load smb0dat with next data byte to transmit. 0 0 x 0100 01x a slave byte was transmitted; error detected. no action required (expecting master to end transfer). 0 0 x 0001 0101 0 x x an illegal stop or bus error was detected while a slave transmission was in progress. clear sto. 00x ? slave receiver 0010 10x a slave address + r/w was received; ack requested. if write, acknowledge received address 0 0 1 0000 if read, load smb0dat with data byte; ack received address 0 0 1 0100 nack received address. 000 ? 11x lost arbitration as master; slave address + r/w received; ack requested. if write, acknowledge received address 0 0 1 0000 if read, load smb0dat with data byte; ack received address 0 0 1 0100 nack received address. 000 ? reschedule failed transfer; nack received address. 1001110 0001 00x a stop was detected while addressed as a slave trans - mitter or slave receiver. clear sto. 00x ? 11x lost arbitration while attempt - ing a stop. no action required (transfer complete/aborted). 000 ? 0000 1 0 x a slave byte was received; ack requested. acknowledge received byte; read smb0dat. 0 0 1 0000 nack received byte. 000 ? bus error condition 0010 0 1 x lost arbitration while attempt - ing a repeated start. abort failed transfer. 00x ? reschedule failed transfer. 10x1110 0001 0 1 x lost arbitration due to a detected stop. abort failed transfer. 00x ? reschedule failed transfer. 10x1110 0000 1 1 x lost arbitration while transmit - ting a data byte as master. abort failed transfer. 000 ? reschedule failed transfer. 1001110 table 22.5. smbus status decoding with hardware ack generation disabled (ehack = 0) (continued) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack www.datasheet.in
rev. 1.0 253 c8051f99x-c8051f98x table 22.6. smbus status decoding with hardware ack generation enabled (ehack = 1) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack master transmitter 1110 0 0 x a master start was gener - ated. load slave address + r/w into smb0dat. 00x1100 1100 000 a master data or address byte was transmitted; nack received. set sta to restart transfer. 10x1110 abort transfer. 01x ? 001 a master data or address byte was transmitted; ack received. load next data byte into smb0dat. 00x1100 end transfer with stop. 01x ? end transfer with stop and start another transfer. 11x ? send repeated start. 10x1110 switch to master receiver mode (clear si without writing new data to smb0dat). set ack for initial data byte. 0 0 1 1000 master receiver 1000 001 a master data byte was received; ack sent. set ack for next data byte; read smb0dat. 0 0 1 1000 set nack to indicate next data byte as the last data byte; read smb0dat. 0 0 0 1000 initiate repeated start. 1001110 switch to master transmitter mode (write to smb0dat before clearing si). 0 0 x 1100 000 a master data byte was received; nack sent (last byte). read smb0dat; send stop. 010 ? read smb0dat; send stop followed by start. 1101110 initiate repeated start. 1001110 switch to master transmitter mode (write to smb0dat before clearing si). 0 0 x 1100 www.datasheet.in
c8051f99x-c8051f98x 254 rev. 1.0 slave transmitter 0100 000 a slave byte was transmitted; nack received. no action required (expecting stop condition). 0 0 x 0001 001 a slave byte was transmitted; ack received. load smb0dat with next data byte to transmit. 0 0 x 0100 01x a slave byte was transmitted; error detected. no action required (expecting master to end transfer). 0 0 x 0001 0101 0 x x an illegal stop or bus error was detected while a slave transmission was in progress. clear sto. 00x ? slave receiver 0010 00x a slave address + r/w was received; ack sent. if write, set ack for first data byte. 0 0 1 0000 if read, load smb0dat with data byte 0 0 x 0100 01x lost arbitration as master; slave address + r/w received; ack sent. if write, set ack for first data byte. 0 0 1 0000 if read, load smb0dat with data byte 0 0 x 0100 reschedule failed transfer 10x1110 0001 00x a stop was detected while addressed as a slave trans - mitter or slave receiver. clear sto. 00x ? 01x lost arbitration while attempt - ing a stop. no action required (transfer complete/aborted). 000 ? 0000 0 0 x a slave byte was received. set ack for next data byte; read smb0dat. 0 0 1 0000 set nack for next data byte; read smb0dat. 0 0 0 0000 bus error condition 0010 0 1 x lost arbitration while attempt - ing a repeated start. abort failed transfer. 00x ? reschedule failed transfer. 10x1110 0001 0 1 x lost arbitration due to a detected stop. abort failed transfer. 00x ? reschedule failed transfer. 10x1110 0000 0 1 x lost arbitration while transmit - ting a data byte as master. abort failed transfer. 00x ? reschedule failed transfer. 10x1110 table 22.6. smbus status decoding with hardware ack generation enabled (ehack = 1) (continued) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack www.datasheet.in
rev. 1.0 255 c8051f99x-c8051f98x 23. uart0 uart0 is an asynchronous, full duplex serial port offering modes 1 and 3 of the standard 8051 uart. enhanced baud rate support allows a wide range of clock sources to generate standard baud rates (details in section ?23.1. enhanced baud rate generation? on page 256 ). received data buffering allows uart0 to start reception of a second incoming data byte be fore software has finished reading the previous data byte. uart0 has two associated sfrs: serial control regist er 0 (scon0) and serial data buffer 0 (sbuf0). the single sbuf0 location provides access to both transmit and receive registers. writes to sbuf0 always access the transmit register. reads of sbuf0 always access the buffered receive register; it is not possible to read data from the transmit register. with uart0 interrupts enabled, an interrupt is generated each time a transmit is completed (ti0 is set in scon0), or a data byte has been received (ri0 is set in scon0). the uart0 interrupt flags are not cleared by hardware when the cpu vectors to the interr upt service routine. they must be cleared manually by software, allowing software to determine the cause of the uart0 interrupt (transmit complete or receive complete). figure 23.1. uart0 block diagram uart baud rate generator ri scon ri ti rb8 tb8 ren mce smode tx control tx clock send sbuf (tx shift) start data write to sbuf crossbar tx shift zero detector tx irq set q d clr stop bit tb8 sfr bus serial port interrupt ti port i/o rx control start rx clock load sbuf shift 0x1ff rb8 rx irq input shift register (9 bits) load sbuf read sbuf sfr bus crossbar rx sbuf (rx latch) www.datasheet.in
c8051f99x-c8051f98x 256 rev. 1.0 23.1. enhanced baud rate generation the uart0 baud rate is generated by timer 1 in 8-bit auto-reload mode. the tx clock is generated by tl1; the rx clock is generated by a copy of tl1 (shown as rx timer in figure 23.2 ), which is not user- accessible. both tx and rx timer overflows are divid ed by two to generate the tx and rx baud rates. the rx timer runs when timer 1 is enabled, and uses the same reload value (th1). however, an rx timer reload is forced when a start condition is de tected on the rx pin. th is allows a receive to begin any time a start is detected, independent of the tx timer state. figure 23.2. uart0 baud rate logic timer 1 should be configured for mode 2, 8-bit auto-reload (see section ?25.1.3. mode 2: 8-bit coun - ter/timer with auto-reload? on page 280 ). the timer 1 reload value should be set so that overflows will occur at two times the desired uart b aud rate frequency. note that timer 1 may be clocked by one of six sources: sysclk, sysclk / 4, sysclk / 12, sysclk / 48, the external oscillator clock / 8, or an exter - nal input t1. for any given timer 1 clock source, the uart0 baud rate is determined by equation 23.1 -a and equation 23.1 -b. equation 23.1. uart0 baud rate where t1 clk is the frequency of the clock supplied to timer 1, and t1h is the high byte of timer 1 (reload value). timer 1 clock frequency is sele cted as described in section ?25.1. timer 0 and timer 1? on page 278 . a quick reference for typical baud rates and system clock frequencies is given in ta b l e 23.1 through ta b l e 23.2 . note that the internal osc illator may still generate the s ystem clock when the external oscillator is driving timer 1. rx timer start detected overflow overflow th1 tl1 tx clock 2 rx clock 2 timer 1 uart uartbaudrate 1 2 -- - t1_overflow_rate ? = t1_overflow_rate t1 clk 256 th1 ? ------------ ------------- - = a) b) www.datasheet.in
rev. 1.0 257 c8051f99x-c8051f98x 23.2. operational modes uart0 provides standard asynchronous, full duplex communication. the uart mode (8-bit or 9-bit) is selected by the s0mode bit (scon0.7). typical uart connection options are shown below. figure 23.3. uart interconnect diagram 23.2.1. 8-bit uart 8-bit uart mode uses a total of 10 bits per data byte: one start bit, eight data bits (lsb first), and one stop bit. data are transmitted lsb first from the tx0 pin a nd received at the rx0 pin. on receive, the eight data bits are stored in sbuf0 and the stop bit goes into rb80 (scon0.2). data transmission begins wh en software writes a data byte to th e sbuf0 register. the ti0 transmit inter - rupt flag (scon0.1) is set at the end of the transmi ssion (the beginning of the stop-bit time). data recep - tion can begin any time after the ren0 rece ive enable bit (scon0.4) is set to logic 1. after the stop bit is received, the data byte w ill be loaded into the sbuf0 re ceive register if the follo wing conditions are met: ri0 must be logic 0, and if mce0 is logic 1, the stop bit must be logic 1. in the event of a receive data over - run, the first received 8 bits are latched into the sbuf0 receive register and the following overrun data bits are lost. if these conditions are met, the eight bits of data is stor ed in sbuf0, the stop bit is stored in rb80 and the ri0 flag is set. if these conditio ns are not met, sbuf0 and rb80 will no t be loaded and the ri0 flag will not be set. an interrupt will occur if enabled when ei ther ti0 or ri0 is set. figure 23.4. 8-bit uart timing diagram or rs-232 c8051fxxx rs-232 level xltr tx rx c8051fxxx rx tx mcu rx tx d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space www.datasheet.in
c8051f99x-c8051f98x 258 rev. 1.0 23.2.2. 9-bit uart 9-bit uart mode uses a total of eleven bits per data byte: a start bit, 8 data bits (lsb first), a programma - ble ninth data bit, and a stop bit. the state of the nint h transmit data bit is determ ined by the value in tb80 (scon0.3), which is assigned by user software. it can be assigned the value of the parity flag (bit p in reg - ister psw) for error detection, or used in multiprocessor communications. on receive, the ninth data bit goes into rb80 (scon0.2) and the stop bit is ignored. data transmission begins when an instruction writes a data byte to the sbuf0 register. the ti0 transmit interrupt flag (scon0.1) is set at the end of the tran smission (the beginning of the stop-bit time). data reception can begin any time after the ren0 receive enab le bit (scon0.4) is set to 1. after the stop bit is received, the data byte w ill be loaded into the sbuf0 re ceive register if the follo wing conditions are met: (1) ri0 must be logic 0, and (2) if mce0 is logic 1, the 9th bit must be logic 1 (when mce0 is logic 0, the state of the ninth data bit is unimportant). if these cond itions are met, the eight bits of data are stored in sbuf0, the ninth bit is stored in rb80, and the ri0 flag is set to 1. if the above conditions are not met, sbuf0 and rb80 will not be loaded and the ri0 flag will not be set to 1. a uart 0 interrupt will occur if enabled when either ti0 or ri0 is set to 1. figure 23.5. 9-bit uart timing diagram 23.3. multiprocessor communications 9-bit uart mode supports multiprocessor communication between a master processor and one or more slave processors by special use of t he ninth data bit. when a master processor wants to transmit to one or more slaves, it first sends an address byte to select th e target(s). an address byte differs from a data byte in that its ninth bit is logic 1; in a data byte, the ninth bit is always set to logic 0. setting the mce0 bit (scon0.5) of a slave processor co nfigures its uart such that when a stop bit is received, the uart will gener ate an interrupt only if the ninth bit is logic 1 (rb80 = 1) signifying an address byte has been received. in the ua rt interrupt handler, software will compare the received address with the slave's own assigned 8-bit addre ss. if the addresses match, the slav e will clear its mce0 bit to enable interrupts on the reception of the following data byte (s). slaves that weren't addressed leave their mce0 bits set and do not generate interrupts on the reception of the following data bytes, thereby ignoring the data. once the entire message is received, the addres sed slave resets its mce0 bit to ignore all transmis - sions until it receives the next address byte. multiple addresses can be assigned to a single sl ave and/or a single address can be assigned to multiple slaves, thereby enabling "broadcast" transmissions to more than one slave simultaneously. the master processor can be configured to receive all transmissi ons or a protocol can be implemented such that the master/slave role is tem porarily reversed to enable half-duplex transmission between the original master and slave(s). d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space d8 www.datasheet.in
rev. 1.0 259 c8051f99x-c8051f98x figure 23.6. uart multi-pr ocessor mode interconnect diagram master device slave device tx rx rx tx slave device rx tx slave device rx tx v+ www.datasheet.in
c8051f99x-c8051f98x 260 rev. 1.0 sfr page = 0x0; sfr address = 0x98; bit-addressable sfr definition 23.1. scon0: serial port 0 control bit 7 6 5 4 3 2 1 0 name s0mode mce0 ren0 tb80 rb80 ti0 ri0 type r/w r r/w r/w r/w r/w r/w r/w reset 01000000 bit name function 7 s0mode serial port 0 operation mode. selects the uart0 operation mode. 0: 8-bit uart with variable baud rate. 1: 9-bit uart with variable baud rate. 6 unused read = 1b. write = don?t care. 5 mce0 multiprocessor comm unication enable. for mode 0 (8-bit uart): ch ecks for vali d stop bit. 0: logic level of stop bit is ignored. 1: ri0 will only be activated if stop bit is logic level 1. for mode 1 (9-bit uart): multip rocessor communica tions enable. 0: logic level of ninth bit is ignored. 1: ri0 is set and an interrupt is gene rated only when the ninth bit is logic 1. 4 ren0 receive enable. 0: uart0 reception disabled. 1: uart0 reception enabled. 3 tb80 ninth transmission bit. the logic level of this bit will be sent as the ninth transmission bi t in 9-bit uart mode (mode 1). unused in 8-bit mode (mode 0). 2 rb80 ninth receive bit. rb80 is assigned the value of the stop bit in mode 0; it is assigned the value of the 9th data bit in mode 1. 1 ti0 transmit interrupt flag. set by hardware when a byte of data has been transmitted by uart0 (after the 8th bit in 8-bit uart mode, or at the beginning of the stop bit in 9-bit uart mode). when the uart0 interrupt is enabled, setting this bit causes the cpu to vector to the uart0 interrupt service routine. this bit must be cleared manually by software. 0 ri0 receive interrupt flag. set to 1 by hardware when a byte of data has been received by uart0 (set at the stop bit sampling time). when the uart0 in terrupt is enabled, setting this bit to 1 causes the cpu to vector to the uart0 in terrupt service routine. this bit must be cleared manually by software. www.datasheet.in
rev. 1.0 261 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x99 sfr definition 23.2. sbuf0: serial (uart0) port data buffer bit 7 6 5 4 3 2 1 0 name sbuf0[7:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:0 sbuf0 serial data buffer bits 7:0 (msb?lsb). this sfr accesses two registers; a transmit shift register and a receive latch register. when data is written to sbuf0, it goes to the transmit shift register and is held for serial transmission. writing a byte to sbuf0 initiates the transm ission. a read of sbuf0 returns the contents of the receive latch. www.datasheet.in
c8051f99x-c8051f98x 262 rev. 1.0 table 23.1. timer settings for standard baud rates using the internal 24.5 mhz oscillator frequency: 24.5 mhz target baud rate (bps) baud rate % error oscilla- tor divide factor timer clock source sca1?sca0 (pre-scale select) 1 t1m 1 timer 1 reload value (hex) sysclk from internal osc. 230400 ?0.32% 106 sysclk xx 2 1 0xcb 115200 ?0.32% 212 sysclk xx 1 0x96 57600 0.15% 426 sysclk xx 1 0x2b 28800 ?0.32% 848 sysclk/4 01 0 0x96 14400 0.15% 1704 sysclk/12 00 0 0xb9 9600 ?0.32% 2544 sysclk/12 00 0 0x96 2400 ?0.32% 10176 sysclk/48 10 0 0x96 1200 0.15% 20448 sysclk/48 10 0 0x2b notes: 1. sca1 ? sca0 and t1m bit definitions can be found in section 25.1 . 2. x = don?t care. table 23.2. timer settings for standard baud rates using an external 22.1184 mhz oscillator frequency: 22.1184 mhz target baud rate (bps) baud rate % error oscilla- tor divide factor timer clock source sca1?sca0 (pre-scale select) 1 t1m 1 timer 1 reload value (hex) sysclk from external osc. 230400 0.00% 96 sysclk xx 2 10xd0 115200 0.00% 192 sysclk xx 1 0xa0 57600 0.00% 384 sysclk xx 1 0x40 28800 0.00% 768 sysclk / 12 00 0 0xe0 14400 0.00% 1536 sysclk / 12 00 0 0xc0 9600 0.00% 2304 sysclk / 12 00 0 0xa0 2400 0.00% 9216 sysclk / 48 10 0 0xa0 1200 0.00% 18432 sysc lk / 48 10 0 0x40 sysclk from internal osc. 230400 0.00% 96 extclk / 8 11 0 0xfa 115200 0.00% 192 extclk / 8 11 0 0xf4 57600 0.00% 384 extclk / 8 11 0 0xe8 28800 0.00% 768 extclk / 8 11 0 0xd0 14400 0.00% 1536 extclk / 8 11 0 0xa0 9600 0.00% 2304 extclk / 8 11 0 0x70 notes: 1. sca1 ? sca0 and t1m bit definitions can be found in section 25.1 . 2. x = don?t care. www.datasheet.in
rev. 1.0 263 c8051f99x-c8051f98x 24. enhanced serial peri pheral interface (spi0) the enhanced serial peripheral interface (spi0) prov ides access to a flexible, full-duplex synchronous serial bus. spi0 can operate as a ma ster or slave device in both 3-wi re or 4-wire modes, and supports multiple masters and slaves on a single spi bus. the slave-select (nss) signal can be configured as an input to select spi0 in slave mode, or to disable ma ster mode operation in a multi-master environment, avoiding contention on the spi bus when more than one master attempts simultaneous data transfers. nss can also be configured as a chip-select output in master mode, or disabled for 3-wire operation. additional general purpose port i/o pins can be used to select multiple slave devices in master mode. figure 24.1. spi block diagram sfr bus data path control sfr bus write spi0dat receive data buffer spi0dat 0 1 2 3 4 5 6 7 shift register spi control logic spi0ckr scr7 scr6 scr5 scr4 scr3 scr2 scr1 scr0 spi0cfg spi0cn pin interface control pin control logic c r o s s b a r port i/o read spi0dat spi irq tx data rx data sck mosi miso nss transmit data buffer clock divide logic sysclk ckpha ckpol slvsel nssmd1 nssmd0 spibsy msten nssin srmt rxbmt spif wcol modf rxovrn txbmt spien www.datasheet.in
c8051f99x-c8051f98x 264 rev. 1.0 24.1. signal descriptions the four signals used by spi0 (mosi, miso, sck, nss) are described below. 24.1.1. master out, slave in (mosi) the master-out, slave-in (mosi) signal is an output fr om a master device and an input to slave devices. it is used to serially transfer data from the master to the slave. this signal is an output when spi0 is operating as a master and an input w hen spi0 is operating as a slave. da ta is transferred most-significant bit first. when configured as a master, mosi is driven by the msb of the shift register in both 3- and 4-wire mode. 24.1.2. master in, slave out (miso) the master-in, slave-out (miso) signal is an output from a slave device and an input to the master device. it is used to serially transfer data from the slave to the master. this signal is an input when spi0 is operating as a master and an output when spi0 is operating as a slave. data is transferred most- significant bit first. the miso pin is placed in a hi gh-impedance state when the spi module is disabled and when the spi operates in 4-wire mode as a slave that is not selected. when acting as a slave in 3-wire mode, miso is always driven by the msb of the shift register. 24.1.3. serial clock (sck) the serial clock (sck) signal is an output from the mast er device and an input to slave devices. it is used to synchronize the transfer of data between the ma ster and slave on the mosi and miso lines. spi0 generates this signal when operating as a master. t he sck signal is ignored by a spi slave when the slave is not selected (nss = 1) in 4-wire slave mode. 24.1.4. slave select (nss) the function of the slave-select (nss) signal is dependent on the setting of the nssmd1 and nssmd0 bits in the spi0cn register. there are three possib le modes that can be selected with these bits: 1. nssmd[1:0] = 00: 3-wire master or 3-wire slave mode: spi0 operates in 3-wire mode, and nss is disabled. when operating as a slave device, spi0 is always selected in 3-wire mode. since no select signal is present, spi0 must be the only slave on th e bus in 3-wire mode. this is intended for point-to- point communication between a master and one slave. 2. nssmd[1:0] = 01: 4-wire slave or multi-master mode: spi0 operates in 4-wire mode, and nss is enabled as an input. when operating as a slave, nss selects the spi0 device. when operating as a master, a 1-to-0 transition of the nss signal disabl es the master function of spi0 so that multiple master devices can be used on the same spi bus. 3. nssmd[1:0] = 1x: 4-wire master mode: spi0 oper ates in 4-wire mode, and nss is enabled as an output. the setting of nssmd0 dete rmines what logic level the nss pin will output. this configuration should only be used when operating spi0 as a master device. see figure 24.2, figure 24.3, and figure 24.4 for typi cal connection diagrams of the various operational modes. note that the setting of nssmd bits affects the pinout of the device. when in 3-wire master or 3-wire slave mode, the nss pin will not be mapped by the crossbar. in all other modes, the nss signal will be mapped to a pin on the device. see section ?21. port input/output? on page 213 for general purpose port i/o and crossbar information. 24.2. spi0 master mode operation a spi master device initiates all data transfers on a spi bus. spi0 is placed in master mode by setting the master enable flag (msten, spi0cn.6). writing a byte of data to the spi0 data register (spi0dat) when in master mode writes to the transmit buffer. if the spi shift register is empty, the byte in the transmit buffer is moved to the shift register, and a data transfer begins. the spi0 master immediately shifts out the data serially on the mosi line while provid ing the serial clock on sck. the spi f (spi0cn.7) flag is set to logic www.datasheet.in
rev. 1.0 265 c8051f99x-c8051f98x 1 at the end of the transfer. if interrupts are enabl ed, an interrupt request is generated when the spif flag is set. while the spi0 master transf ers data to a slave on the mosi line, the addressed spi slave device simultaneously transfers the contents of its shift register to the spi master on the miso line in a full-duplex operation. therefore, the spif flag serves as both a transmit-complete and receive-data-ready flag. the data byte received from the slave is transferred msb-fi rst into the master's shift register. when a byte is fully shifted into the register, it is moved to the receive buffer where it can be read by the processor by reading spi0dat. when configured as a master, spi0 can operate in one of three different modes: multi-master mode, 3-wire single-master mode, and 4-wire single-master mode. the default, multi-master mode is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0cn.2) = 1. in this mode, nss is an input to the device, and is used to disable the master spi0 when another mast er is accessing the bus. when nss is pulled low in this mode, msten (spi0cn.6) and spien (spi0cn.0) ar e set to 0 to disable the spi master device, and a mode fault is generate d (modf, spi0cn.5 = 1). mode fault will gen erate an inte rrupt if e nabled. spi0 must be manually re-enabled in soft ware under these circumstances. in multi-master systems, devices will typically default to being slave devices while they are not acting as the system master device. in multi- master mode, slave devices can be addressed indivi dually (if needed) using general-purpose i/o pins. figure 24.2 shows a connection diagram between two master devices in multiple-mas ter mode. 3-wire single-master mode is active when nssmd1 (s pi0cn.3) = 0 and nssmd0 ( spi0cn.2) = 0. in this mode, nss is not used, and is not mapped to an exte rnal port pin through the crossbar. any slave devices that must be addressed in this mode should be selected using general-purpose i/o pins. figure 24.3 shows a connection diagram between a master dev ice in 3-wire master mode and a slave device. 4-wire single-master mode is active wh en nssmd1 (spi0cn.3) = 1. in this mode, nss is configured as an output pin, and can be used as a sl ave-select signal for a single spi dev ice. in this mode, the output value of nss is controlled (in software) with the bit nssm d0 (spi0cn.2). additional slave devices can be addressed using general-purpose i/o pins. figure 24.4 shows a connection diagram for a master device in 4-wire master mode and two slave devices. figure 24.2. multiple-master mode connection diagram figure 24.3. 3-wire single master and 3-wire single slave mode connection diagram master device 2 master device 1 mosi miso sck miso mosi sck nss gpio nss gpio slave device master device mosi miso sck miso mosi sck www.datasheet.in
c8051f99x-c8051f98x 266 rev. 1.0 figure 24.4. 4-wire single master mode and 4-wire slave mode connection diagram 24.3. spi0 slave mode operation when spi0 is enabled and not confi gured as a master, it will operate as a spi slave. as a slave, bytes are shifted in through the mosi pin and out through th e miso pin by a master device controlling the sck signal. a bit counter in the spi0 logic counts sck edges. when 8 bits have been shifted through the shift register, the spif flag is set to logic 1, and the byte is copied into the receive buffer. data is read from the receive buffer by reading spi0dat. a slave device cannot initiate transfers. data to be transferred to the master device is pre-loaded into the shift register by writing to spi0dat. writes to spi0dat are double- buffered, and are placed in the transmit buffer first. if the shift register is empty, the contents of the transmit buffer will immediately be transferred into the shift register. when the sh ift register already contains data, the spi will load the shift register wi th the transmit buffer?s contents af ter the last sck edg e of the next (or current) spi transfer. when configured as a slave, spi0 can be configured for 4-wire or 3-wire operation. the default, 4-wire slave mode, is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0cn.2) = 1. in 4-wire mode, the nss signal is routed to a port pin and configured as a digital input. spi0 is enabl ed when nss is logic 0, and disabled when nss is logic 1. the bit counter is rese t on a falling edge of nss. note that the nss signal must be driven low at least 2 system clocks be fore the first active edge of sck for each byte transfer. figure 24.4 shows a connection diagram be tween two slave devices in 4-wire slave mode and a master device. 3-wire slave mode is active when nssmd1 (spi0cn. 3) = 0 and nssmd0 (spi0cn.2) = 0. nss is not used in this mode, and is not mapped to an external port pin through the crossbar. since there is no way of uniquely addressing the device in 3-wire slave mode , spi0 must be the only slav e device present on the bus. it is important to note that in 3-wire slave mode there is no external means of resetting the bit counter that determines when a full byte has been received. th e bit counter can only be reset by disabling and re- enabling spi0 with the spien bit. figure 24.3 shows a connection diagram between a slave device in 3- wire slave mode and a master device. slave device master device mosi miso sck miso mosi sck nss nss gpio slave device mosi miso sck nss www.datasheet.in
rev. 1.0 267 c8051f99x-c8051f98x 24.4. spi0 interrupt sources when spi0 interrupts are e nabled, the following four flags will gener ate an interrupt when they are set to logic 1: all of the following bits must be cleared by software. ? the spi interrupt flag, spif (spi0cn.7) is set to logic 1 at the end of each byte transfer. this flag can occur in all spi0 modes. ? the write collision flag, wcol (spi0cn.6) is set to logic 1 if a write to spi0dat is attempted when the transmit buffer has not been emptied to the spi shift register. when this occurs, the write to spi0dat will be ignored, and the tr ansmit buffer will not be writte n.this flag can occur in all spi0 modes. ? the mode fault flag modf (spi0cn.5) is set to logi c 1 when spi0 is configured as a master, and for multi-master mode and the nss pin is pulled low. when a mode fault occurs, the msten and spien bits in spi0cn are set to logic 0 to disable spi0 an d allow another master device to access the bus. ? the receive overrun flag rxovrn (spi0cn.4) is se t to logic 1 when configured as a slave, and a transfer is completed and the rece ive buffer still holds an unread byte from a prev ious transfer. the new byte is not transferred to the receive buffer, allowing the previously received data byte to be read. the data byte which caused the overrun is lost. 24.5. serial clock phase and polarity four combinations of serial clock phase and polarity can be selected using the clock control bits in the spi0 configuration register (spi0c fg). the ckpha bit ( spi0cfg.5) selects one of two clock phases (edge used to latch the data). the ckpol bit (spi0cfg.4) selects between an active-high or active-low clock. both master and slave devices must be config ured to use the same clock phase and polarity. spi0 should be disabled (by clearing the spien bit, spi0 cn.0) when changing the clock phase or polarity. the clock and data line relationships for master mode are shown in figure 24.5. for slave mode, the clock and data relationships are shown in figure 24.6 and figure 24.7. note that ckpha should be set to 0 on both the master and slave spi when communicat ing between two silicon labs c8051 devices. the spi0 clock rate register (spi0c kr) as shown in sfr definition 24.3 controls the master mode serial clock frequency. this register is ignored when operating in slave mode. when the spi is configured as a master, the maximum data transfer rate (bits/sec) is one-half the s ystem clock frequency or 12.5 mhz, whichever is slower. when the spi is configured as a sl ave, the maximum data transfer rate (bits/sec) for full-duplex operation is 1/10 the system clock frequency , provided that the master issues sck, nss (in 4- wire slave mode), and the serial input data synchrono usly with the slave?s system clock. if the master issues sck, nss, and the serial input data asynchronously, the maximum data transfer rate (bits/sec) must be less than 1/10 the system clock frequency. in the special case where the master only wants to transmit data to the slave and does not need to receive data from the slave (i.e. half-duplex operation), the spi slave can receive data at a maximum data transfer rate (bits/sec) of 1/4 the system clock frequency. this is provided that the master i ssues sck, nss, and the serial inpu t data synchronously with the slave?s system clock. www.datasheet.in
c8051f99x-c8051f98x 268 rev. 1.0 figure 24.5. master mode data/clock timing figure 24.6. slave mode data/clock timing (ckpha = 0) sck (ckpol=0, ckpha=0) sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=0) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso/mosi nss (must remain high in multi-master mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi sck (ckpol=0, ckpha=0) sck (ckpol=1, ckpha=0) www.datasheet.in
rev. 1.0 269 c8051f99x-c8051f98x figure 24.7. slave mode data/clock timing (ckpha = 1) 24.6. spi special function registers spi0 is accessed and controlled through four special function registers in the system controller: spi0cn control register, spi0dat data re gister, spi0cfg configuration register, and spi0ckr clock rate register. the four special function registers related to the operation of the spi0 bus are described in the following figures. sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi www.datasheet.in
c8051f99x-c8051f98x 270 rev. 1.0 sfr page = 0x0; sfr address = 0xa1 sfr definition 24.1. spi0c fg: spi0 configuration bit7654321 0 name spibsy msten ckpha ckpol slvsel nssin srmt rxbmt type r r/w r/w r/w r r r r reset 0000011 1 bit name function 7 spibsy spi busy. this bit is set to logic 1 when a spi transf er is in progress (master or slave mode). 6 msten master mode enable. 0: disable master mode. operate in slave mode. 1: enable master mode. operate as a master. 5 ckpha spi0 clock phase. 0: data centered on first edge of sck period. * 1: data centered on second edge of sck period. * 4ckpol spi0 clock polarity. 0: sck line low in idle state. 1: sck line high in idle state. 3 slvsel slave selected flag. this bit is set to logic 1 whenever the nss pin is low indicating spi0 is the selected slave. it is cleared to logic 0 when nss is high (slave not sele cted). this bit does not indicate the instantaneous value at th e nss pin, but rather a de-glitched ver- sion of the pin input. 2 nssin nss instantaneous pin input. this bit mimics the instantaneous value that is present on the nss port pin at the time that the register is read. this input is not de-glitched. 1srmt shift register empty (valid in slave mode only). this bit will be set to logic 1 when all data has been tran sferred in/out of the shift register, and there is no new information avai lable to read from the transmit buffer or write to the receive buffer . it returns to logic 0 when a data byte is transferred to the shift register from the transmit buffer or by a transition on sck. srmt = 1 when in master mode. 0 rxbmt receive buffer empty (valid in slave mode only). this bit will be set to logic 1 when the re ceive buffer has been read and contains no new information. if there is new informatio n available in the receive buffer that has not been read, this bit will return to logic 0. rxbmt = 1 when in master mode. note: in slave mode, data on mosi is sampl ed in the center of each data bit. in master mode, data on miso is sampled one sysclk before the end of each data bit, to provide maximum settling time for the slave device. see table 24.1 for timing parameters. www.datasheet.in
rev. 1.0 271 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xf8; bit-addressable sfr definition 24.2. spi0cn: spi0 control bit7654321 0 name spif wcol modf rxovrn nssmd[1:0] txbmt spien type r/w r/w r/w r/w r/w r r/w reset 0000011 0 bit name function 7 spif spi0 interrupt flag. this bit is set to logic 1 by hardware at the end of a data transfer. if spi interrupts are enabled, an inte rrupt will be gene rated. this bit is not automatically cleared by hardware, and must be cleared by software. 6wcol write collision flag. this bit is set to logic 1 if a write to spi0dat is attempted when txbmt is 0. when this occurs, the write to spi0dat will be i gnored, and th e transmit buffer will not be written. if spi interrupts are enabled, an in terrupt will be generated. this bit is not automatically cleared by hardware, and must be cleared by software. 5modf mode fault flag. this bit is set to logic 1 by hardware w hen a master mode co llision is detected (nss is low, msten = 1, and nssmd[1:0] = 01). if spi interrupts are enabled, an interrupt will be generat ed. this bit is not automatica lly cleared by hardware, and must be cleared by software. 4 rxovrn receive overrun flag (valid in slave mode only). this bit is set to logic 1 by hardware w hen the receive buffer still holds unread data from a previous transfer and the last bit of the current transfer is shifted into the spi0 shift register. if spi inte rrupts are enabled, an interr upt will be generated. this bit is not automatically cleared by hardware, and must be cleared by software. 3:2 nssmd[1:0] slave select mode. selects between the following nss operation modes: (see section 24.2 and section 24.3). 00: 3-wire slave or 3-wire master mode. nss signal is not routed to a port pin. 01: 4-wire slave or multi-master mode (d efault). nss is an input to the device. 1x: 4-wire single-master mode. nss sign al is mapped as an output from the device and will assume the value of nssmd0. 1 txbmt transmit buffer empty. this bit will be set to logic 0 when new da ta has been written to the transmit buffer. when data in the transmit buff er is transferred to the spi shift register, this bit will be set to logic 1, indicating that it is safe to write a new byte to the transmit buffer. 0 spien spi0 enable. 0: spi disabled. 1: spi enabled. www.datasheet.in
c8051f99x-c8051f98x 272 rev. 1.0 sfr page = 0x0; sfr address = 0xa2 sfr page = 0x0; sfr address = 0xa3 sfr definition 24.3. spi 0ckr: spi0 clock rate bit7654321 0 name scr[7:0] type r/w reset 0000000 0 bit name function 7:0 scr[7:0] spi0 clock rate. these bits determine the frequency of the sck output when the spi0 module is configured for master mode operation. the sck clock frequency is a divided ver- sion of the system clock, and is given in the following equation, where sysclk is the system clock frequency and spi0ckr is the 8-bit value held in the spi0ckr register. for 0 <= spi0ckr <= 255 example: if sysclk = 2 mhz and spi0ckr = 0x04, sfr definition 24.4. spi0dat: spi0 data bit7654321 0 name spi0dat[7:0] type r/w reset 0000000 0 bit name function 7:0 spi0dat[7:0] spi0 transmit and receive data. the spi0dat register is used to transmit and receive spi0 data. writing data to spi0dat places the data into the transmi t buffer and initiates a transfer when in master mode. a read of spi0dat returns the contents of the receive buffer. f sck sysclk 2 spi0ckr[7:0] 1 + ?? ? ------------------- ---------------------- ----------------- - = f sck 2000000 241 + ?? ? --------------- ----------- = f sck 200 khz = www.datasheet.in
rev. 1.0 273 c8051f99x-c8051f98x figure 24.8. spi master timing (ckpha = 0) figure 24.9. spi master timing (ckpha = 1) sck* t mckh t mckl mosi t mis miso * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mih sck* t mckh t mckl miso t mih mosi * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mis www.datasheet.in
c8051f99x-c8051f98x 274 rev. 1.0 figure 24.10. spi slave timing (ckpha = 0) figure 24.11. spi slave timing (ckpha = 1) sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t sez t sdz sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t slh t sez t sdz www.datasheet.in
rev. 1.0 275 c8051f99x-c8051f98x table 24.1. spi slave timing parameters parameter description min max units master mode timing (see figure 24.8 and figure 24.9) t mckh sck high time 1 x t sysclk ?ns t mckl sck low time 1 x t sysclk ?ns t mis miso valid to sck shift edge 1 x t sysclk + 20 ? ns t mih sck shift edge to miso change 0 ? ns slave mode timing (see figure 24.10 and figure 24.11) t se nss falling to firs t sck edge 2 x t sysclk ?ns t sd last sck edge to nss rising 2 x t sysclk ?ns t sez nss falling to miso valid ? 4 x t sysclk ns t sdz nss rising to miso high-z ? 4 x t sysclk ns t ckh sck high time 5 x t sysclk ?ns t ckl sck low time 5 x t sysclk ?ns t sis mosi valid to sck sample edge 2 x t sysclk ?ns t sih sck sample edge to mosi change 2 x t sysclk ?ns t soh sck shift edge to miso change ? 4 x t sysclk ns t slh last sck edge to miso change ? (ckpha = 1 only) 6 x t sysclk 8 x t sysclk ns note: t sysclk is equal to one per iod of the device syst em clock (sysclk). www.datasheet.in
c8051f99x-c8051f98x 276 rev. 1.0 25. timers each mcu includes four counter/timers: two are 16-bit counter/timers compatible with those found in the standard 8051, and two are 16-bit auto-reload timer fo r use with the adc, smbus, or for general purpose use. these timers can be used to measure time inte rvals, count external even ts and generate periodic interrupt requests. timer 0 and timer 1 are nearly identical and have four primary modes of operation. timer 2 and timer 3 offer 16-bit and split 8-bit timer functionality with auto-reload. additionally, timer 2 and timer 3 have a capture mode that can be used to me asure the smartclock or a comparator period with respect to another oscillator. this is pa rticularly useful when using capacitive touch switches. see application note an338 for details on capacitive touch switch sensing. timers 0 and 1 may be clocked by one of five sources, determined by the timer mode select bits (t1m ? t0m) and the clock scale bits (sca1?sca0). the clock scale bits define a pre- scaled clock from which timer 0 and/or timer 1 may be clocked (see sfr definition 25.1 for pre-scaled cl ock selection). timer 0/1 may then be configured to use this pre-sc aled clock signal or th e system clock. timer 2 and timer 3 may be clocked by the system clock, the system clock divided by 12. timer 2 may additionally be clocked by the smartclock divided by 8 or the comparator0 output. timer 3 may additionally be clocked by the external oscillator clock source divided by 8 or the comparator 1 output. timer 0 and timer 1 may also be operated as counters. when functioning as a counter, a counter/timer register is incremented on each high-to-low transition at the selected input pin (t0 or t1). events with a frequency of up to one-fourth the system clock frequency can be counted. the input signal need not be periodic, but it should be held at a given level for at least two full system clock cycles to ensure the level is properly sampled. timer 0 and timer 1 modes timer 2 modes timer 3 modes 13-bit counter/timer 16-bit timer with auto-reload 16-bit timer with auto-reload 16-bit counter/timer 8-bit counter/timer with auto- reload two 8-bit timers with auto-reload t wo 8-bit timers with auto-reload two 8-bit counter/timers (timer 0 only) www.datasheet.in
rev. 1.0 277 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x8e sfr definition 25.1. ckcon: clock control bit 7 6 5 4 3 2 1 0 name t3mh t3ml t2mh t2ml t1m t0m sca[1:0] type r/w r/w r/w r/w r/w r/w r/w reset 0 0 0 0 0 0 0 0 bit name function 7 t3mh timer 3 high byte clock select. selects the clock supplied to the timer 3 high byte (split 8-bit timer mode only). 0: timer 3 high byte uses the clock defin ed by the t3xclk bit in tmr3cn. 1: timer 3 high byte uses the system clock. 6 t3ml timer 3 low byte clock select. selects the clock supplied to timer 3. selects the clock supplie d to the lower 8-bit timer in split 8-bit timer mode. 0: timer 3 low byte uses the clock defined by the t3xclk bit in tmr3cn. 1: timer 3 low byte uses the system clock. 5 t2mh timer 2 high byte clock select. selects the clock supplied to the timer 2 high byte (split 8-bit timer mode only). 0: timer 2 high byte uses the clock defin ed by the t2xclk bit in tmr2cn. 1: timer 2 high byte uses the system clock. 4 t2ml timer 2 low byte clock select. selects the clock supplied to timer 2. if timer 2 is configured in split 8-bit timer mode, this bit selects the clock supp lied to the lower 8-bit timer. 0: timer 2 low byte uses the clock defined by the t2xclk bit in tmr2cn. 1: timer 2 low byte uses the system clock. 3 t1m timer 1 clock select. selects the clock source supplied to timer 1. ignored when c/t1 is set to 1. 0: timer 1 uses the clock defined by the prescale bits sca[1:0]. 1: timer 1 uses the system clock. 2 t0m timer 0 clock select. selects the clock source supplied to timer 0. ignored when c/t0 is set to 1. 0: counter/timer 0 uses the clock defined by the prescale bits sca[1:0]. 1: counter/timer 0 uses the system clock. 1:0 sca[1:0] timer 0/1 prescale bits. these bits control the timer 0/1 clock prescaler: 00: system clock divided by 12 01: system clock divided by 4 10: system clock divided by 48 11: external clock divided by 8 (synchronized with the system clock) www.datasheet.in
c8051f99x-c8051f98x 278 rev. 1.0 25.1. timer 0 and timer 1 each timer is implemented as a 16-bit register acce ssed as two separate bytes: a low byte (tl0 or tl1) and a high byte (th0 or th1). the counter/timer co ntrol register (tcon) is used to enable timer 0 and timer 1 as well as indicate status. timer 0 interrupts can be enabled by setting the et0 bit in the ie regis - ter ( ?interrupt register descriptions? on page 140 ); timer 1 interrupts can be enabled by setting the et1 bit in the ie register ( ?interrupt register descriptions? on page 140 ). both counter/timers operate in one of four primary modes selected by setting the mode select bits t1m1 ? t0m0 in the counter/timer mode register (tmod). each timer can be configured independen tly. each operating mode is described below. 25.1.1. mode 0: 13-bit counter/timer timer 0 and timer 1 operate as 13-bit counter/timers in mode 0. the following describes the configuration and operation of timer 0. however, both timers operate identically, and timer 1 is configured in the same manner as described for timer 0. the th0 register holds the eight msbs of the 13-bit c ounter/timer. tl0 holds the five lsbs in bit positions tl0.4 ? tl0.0. the three upper bits of tl0 (tl0.7 ? tl0.5) are indeterminate and should be masked out or ignored when reading. as the 13-bit timer register increments and overflows from 0x1fff (all ones) to 0x0000, the timer overflow flag tf0 (tcon.5) is set and an interr upt will occur if timer 0 interrupts are enabled. the c/t0 bit (tmod.2) selects the counter/time r's clock source. when c/t0 is set to logic 1, high-to-low transitions at the selected timer 0 input pin (t0) increment the timer register (refer to section ?21.3. priority crossbar decoder? on page 217 for information on selecting and configuring external i/o pins). clearing c/t selects the clock defined by the t0m bit (ckcon.3). when t0m is set, timer 0 is clocked by the system clock. when t0m is cleared, timer 0 is clocked by the source selected by the clock scale bits in ckcon (see sfr definition 25.1 ). setting the tr0 bit (tcon.4) enables the ti mer when either gate0 (tmod.3) is logic 0 or the input signal int0 is active as defined by bit in 0pl in register it01cf (see sfr definition 13.7 ). setting gate0 to 1 allows the timer to be controlled by the external input signal int0 (see section ?13.5. interrupt register descriptions? on page 140 ), facilitating pulse width measurements setting tr0 does not force the timer to reset. the timer registers should be loaded with the desired initial value before the timer is enabled. tl1 and th1 form the 13-bit register for timer 1 in the same manner as described above for tl0 and th0. timer 1 is configured and controlled using the releva nt tcon and tmod bits just as with timer 0. the input signal int1 is used with timer 1; the int1 polarity is defined by bit in1pl in register it01cf (see sfr definition 13.7 ). table 25.1. timer 0 running modes tr0 gate0 int0 counter/timer 0 x x disabled 1 0 x enabled 1 1 0 disabled 1 1 1 enabled note: x = don't care www.datasheet.in
rev. 1.0 279 c8051f99x-c8051f98x figure 25.1. t0 mode 0 block diagram 25.1.2. mode 1: 16-bit counter/timer mode 1 operation is the same as mode 0, except that the counter /timer registers use all 16 bits. the coun - ter/timers are enabled and configured in mode 1 in the same manner as for mode 0. tclk tl0 (5 bits) th0 (8 bits) tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt tr0 0 1 0 1 sysclk pre-scaled clock ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmod t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 gate0 int0 t0 crossbar it01cf i n 1 s l 1 i n 1 s l 0 i n 1 s l 2 i n 1 p l i n 0 p l i n 0 s l 2 i n 0 s l 1 i n 0 s l 0 in0pl xor www.datasheet.in
c8051f99x-c8051f98x 280 rev. 1.0 25.1.3. mode 2: 8-bit counter/timer with auto-reload mode 2 configures timer 0 and timer 1 to operate as 8-bit counter/timers with automatic reload of the start value. tl0 holds the count and th0 holds the reload va lue. when the counter in tl0 overflows from all ones to 0x00, the timer over flow flag tf0 (tcon.5) is set and the co unter in tl0 is reloaded from th0. if timer 0 interrupts are enabled, an interr upt will occur when the tf0 flag is set. the reload value in th0 is not changed. tl0 must be initialized to the desired va lue before enabling the timer for the first count to be correct. when in mode 2, timer 1 operates identically to timer 0. both counter/timers are enabled and configured in mode 2 in the same manner as mode 0. setting the tr0 bit (tcon.4) enables the timer when either gate0 (tmod.3) is logic 0 or when the input signal int0 is active as defined by bit in 0pl in register it01cf (see section ?13.6. external interrupts int0 and int1? on page 147 for details on the external input signals int0 and int1 ). figure 25.2. t0 mode 2 block diagram tclk tmod t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt tl0 (8 bits) reload th0 (8 bits) 0 1 0 1 sysclk pre-scaled clock it01cf i n 1 s l 1 i n 1 s l 0 i n 1 s l 2 i n 1 p l i n 0 p l i n 0 s l 2 i n 0 s l 1 i n 0 s l 0 tr0 gate0 in0pl xor int0 t0 crossbar ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m www.datasheet.in
rev. 1.0 281 c8051f99x-c8051f98x 25.1.4. mode 3: two 8-bit counter/timers (timer 0 only) in mode 3, timer 0 is configured as two separate 8-bit co unter/timers held in tl0 and th0. the coun - ter/timer in tl0 is co ntrolled using the timer 0 control/status bits in tcon and tmod: tr0, c/t0, gate0 and tf0. tl0 can use either the system clock or an ex ternal input signal as its timebase. the th0 register is restricted to a timer function so urced by the system clock or presca led clock. th0 is enabled using the timer 1 run control bit tr1. th0 sets the timer 1 overflow flag tf1 on overfl ow and thus controls the timer 1 interrupt. timer 1 is inactive in mode 3. when timer 0 is operating in mode 3, timer 1 can be operated in modes 0, 1 or 2, but cannot be clocked by external signals nor set the tf1 flag and generate an interrupt. however, the timer 1 overflow can be used to generate baud rates for the smbus and/or uart, and/or initiate adc conversions. while timer 0 is operating in mode 3, timer 1 run control is handled through its mode set - tings. to run timer 1 while timer 0 is in mode 3, set the timer 1 mode as 0, 1, or 2. to disable timer 1, configure it for mode 3. figure 25.3. t0 mode 3 block diagram tl0 (8 bits) tmod 0 1 tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt interrupt 0 1 sysclk pre-scaled clock tr1 th0 (8 bits) t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 tr0 gate0 in0pl xor int0 t0 crossbar ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m www.datasheet.in
c8051f99x-c8051f98x 282 rev. 1.0 sfr page = 0x0; sfr address = 0x88; bit-addressable sfr definition 25.2. tcon: timer control bit 7 6 5 4 3 2 1 0 name tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7 tf1 timer 1 overflow flag. set to 1 by hardware when timer 1 overflows. this flag can be cleared by software but is automatically cleared when the cpu vectors to the timer 1 interrupt service routine. 6 tr1 timer 1 run control. timer 1 is enabled by setting this bit to 1. 5 tf0 timer 0 overflow flag. set to 1 by hardware when timer 0 overflows. this flag can be cleared by software but is automatically cleared when the cpu vectors to the timer 0 interrupt service routine. 4 tr0 timer 0 run control. timer 0 is enabled by setting this bit to 1. 3 ie1 external interrupt 1. this flag is set by hardware when an edge/l evel of type defined by it1 is detected. it can be cleared by software but is automatically cleared when the cpu vectors to the external interrupt 1 service routine in edge-triggered mode. 2 it1 interrupt 1 type select. this bit selects whether the configured int1 interrupt will be edge or level sensitive. int1 is configured active low or high by the in1pl bit in the it01cf register (see sfr definition 13.7 ). 0: int1 is level triggered. 1: int1 is edge triggered. 1 ie0 external interrupt 0. this flag is set by hardware when an edge/l evel of type defined by it1 is detected. it can be cleared by software but is automatically cleared when the cpu vectors to the external interrupt 0 service routine in edge-triggered mode. 0 it0 interrupt 0 type select. this bit selects whether the configured int0 interrupt will be edge or level sensitive. int0 is configured active low or high by the in0pl bit in register it01cf (see sfr definition 13.7 ). 0: int0 is level triggered. 1: int0 is edge triggered. www.datasheet.in
rev. 1.0 283 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x89 sfr definition 25.3. tmod: timer mode bit 7 6 5 4 3 2 1 0 name gate1 c/t1 t1m[1:0] gate0 c/t0 t0m[1:0] type r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7 gate1 timer 1 gate control. 0: timer 1 enabled when tr1 = 1 irrespective of int1 logic level. 1: timer 1 enabled only when tr1 = 1 and int1 is active as defined by bit in1pl in register it01cf (see sfr definition 13.7 ). 6 c/t1 counter/timer 1 select. 0: timer: timer 1 incremented by clock defined by t1m bit in register ckcon. 1: counter: timer 1 incremented by high-to-low transitions on external pin (t1). 5:4 t1m[1:0] timer 1 mode select. these bits select the timer 1 operation mode. 00: mode 0, 13-bit counter/timer 01: mode 1, 16-bit counter/timer 10: mode 2, 8-bit counter/timer with auto-reload 11: mode 3, timer 1 inactive 3 gate0 timer 0 gate control. 0: timer 0 enabled when tr0 = 1 irrespective of int0 logic level. 1: timer 0 enabled only when tr0 = 1 and int0 is active as defined by bit in0pl in register it01cf (see sfr definition 13.7 ). 2 c/t0 counter/timer 0 select. 0: timer: timer 0 incremented by clock defined by t0m bit in register ckcon. 1: counter: timer 0 incremented by high-to-low transitions on external pin (t0). 1:0 t0m[1:0] timer 0 mode select. these bits select the timer 0 operation mode. 00: mode 0, 13-bit counter/timer 01: mode 1, 16-bit counter/timer 10: mode 2, 8-bit counter/timer with auto-reload 11: mode 3, two 8-bit counter/timers www.datasheet.in
c8051f99x-c8051f98x 284 rev. 1.0 sfr page = 0x0; sfr address = 0x8a sfr page = 0x0; sfr address = 0x8b sfr definition 25.4. tl0: timer 0 low byte bit 7 6 5 4 3 2 1 0 name tl0[7:0] type r/w reset 00000000 bit name function 7:0 tl0[7:0] timer 0 low byte. the tl0 register is the low byte of the 16-bit timer 0. sfr definition 25.5. tl1: timer 1 low byte bit 7 6 5 4 3 2 1 0 name tl1[7:0] type r/w reset 00000000 bit name function 7:0 tl1[7:0] timer 1 low byte. the tl1 register is the low byte of the 16-bit timer 1. www.datasheet.in
rev. 1.0 285 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x8c sfr page = 0x0; sfr address = 0x8d sfr definition 25.6. th0: timer 0 high byte bit 7 6 5 4 3 2 1 0 name th0[7:0] type r/w reset 00000000 bit name function 7:0 th0[7:0] timer 0 high byte. the th0 register is the high byte of the 16-bit timer 0. sfr definition 25.7. th1: timer 1 high byte bit 7 6 5 4 3 2 1 0 name th1[7:0] type r/w reset 00000000 bit name function 7:0 th1[7:0] timer 1 high byte. the th1 register is the high byte of the 16-bit timer 1. www.datasheet.in
c8051f99x-c8051f98x 286 rev. 1.0 25.2. timer 2 timer 2 is a 16-bit timer formed by two 8-bit sfrs: tmr2l (low byte) and tmr2h (high byte). timer 2 may operate in 16-bit auto-reload mode or (split) 8-bit auto-reload mode. the t2split bit (tmr2cn.3) defines the timer 2 operation mode. timer 2 can also be used in capture mode to measure the smartclock or the comparator 0 period with respect to anot her oscillator. the ability to measure the comparator 0 period with respect to the system clock is make s using touch sense switches very easy. timer 2 may be clocked by the system cl ock, the system clock divided by 12, smartclock divided by 8, or comparator 0 output. note that the smartclock divided by 8 and comparator 0 output is synchronized with the system clock. 25.2.1. 16-bit timer with auto-reload when t2split (tmr2cn. 3) is zero, timer 2 operates as a 16-bit time r with auto-reload. timer 2 can be clocked by sysclk, sysclk divided by 12, smartclock divided by 8, or comparator 0 output. as the 16-bit timer register increments and overflows from 0xffff to 0x0000, the 16-bit value in the timer 2 reload registers (tmr2rlh and tmr2rll) is loaded into the timer 2 register as shown in figure 25.4 , and the timer 2 high byte overflow flag (tmr2cn.7) is set. if timer 2 interrupts are enabled (if ie.5 is set), an interrupt will be gen erated on each timer 2 overflow. additionally, if timer 2 interrupts are enabled and the tf2len bit is set (tmr2cn. 5), an interr upt will be generated each time the lower 8 bits (tmr2l) overflow from 0xff to 0x00. figure 25.4. timer 2 16-bit mode block diagram sysclk tmr2l tmr2h tmr2rll tmr2rlh reload tclk 0 1 tr2 tmr2cn t2split tf2cen tf2l tf2h t2xclk tr2 interrupt tf2len to adc, smbus to smbus tl2 overflow ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m smartclock / 8 sysclk / 12 00 t2xclk[1:0] 01 11 comparator 0 www.datasheet.in
rev. 1.0 287 c8051f99x-c8051f98x 25.2.2. 8-bit timers with auto-reload when t2split is set, timer 2 operates as two 8-bit timers (tmr2h and tmr2l). both 8-bit timers oper - ate in auto-reload mode as shown in figure 25.5 . tmr2rll holds the reload value for tmr2l; tmr2rlh holds the reload value for tmr2h. the tr2 bit in tmr2cn handles the run control for tmr2h. tmr2l is always running when configured for 8-bit mode. each 8-bit timer may be configur ed to use sysclk, sysclk divided by 12, smartclock divided by 8 or comparator 0 output. the timer 2 clock select bits (t2mh and t2ml in ckcon) select either sysclk or the clock defined by the timer 2 external clock select bits (t2x clk[1:0] in tmr2 cn), as follows: the tf2h bit is set when tmr2h overflows from 0xff to 0x00; the tf2l bit is set when tmr2l overflows from 0xff to 0x00. when timer 2 interrupts are enabled (ie.5), an interrupt is generated each time tmr2h overflows. if timer 2 interrupts are enabled and tf2len (tmr2cn.5) is set, an interrupt is gener - ated each time either tmr2l or tmr2h overflows. when tf2len is enabled, software must check the tf2h and tf2l flags to determine the source of the timer 2 interrupt. the tf2h and tf2l interrupt flags are not cleared by hardware and must be manually cleared by software. figure 25.5. timer 2 8-bit mode block diagram t2mh t2xclk[1:0] tmr2h clock source t2ml t2xclk[1:0] tmr2l clock source 0 00 sysclk / 12 0 00 sysclk / 12 0 01 smartclock / 8 0 01 smartclock / 8 0 10 reserved 0 10 reserved 0 11 comparator 0 0 11 comparator 0 1 x sysclk 1 x sysclk sysclk tclk 0 1 tr2 1 0 tmr2h tmr2rlh reload reload tclk tmr2l tmr2rll interrupt tmr2cn t2split tf2cen tf2len tf2l tf2h t2xclk tr2 to adc, smbus to smbus ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m smartclock / 8 sysclk / 12 00 t2xclk[1:0] 01 11 comparator 0 www.datasheet.in
c8051f99x-c8051f98x 288 rev. 1.0 25.2.3. comparator 0/smartclock capture mode the capture mode in timer 2 allows either comparator 0 or the smartclock period to be measured against the system clock or the system clock divided by 12. comparator 0 and the smartclock period can also be compared against each other. timer 2 capture mode is enabled by setting tf2cen to 1. timer 2 should be in 16-bit auto-reload mode when using capture mode. when capture mode is enable d, a capture event will be gener ated either ev ery comparator 0 rising edge or every 8 smartclock clock cycles, depending on th e t2xclk1 setting. when the capture event occurs, the contents of timer 2 (tmr2h:tmr2l) are loaded into the timer 2 reload registers (tmr2rlh:tmr2rll) and the tf2h flag is set (triggering an interrupt if timer 2 interrupts are enabled). by recording the difference between two succ essive timer capture values, the comparator 0 or smart - clock period can be determined with respect to the timer 2 clock. the timer 2 clock should be much faster than the capture clock to achieve an accurate reading. for example, if t2ml = 1b, t2xclk1 = 0b, and tf2cen = 1b, timer 2 will clock every sysclk and cap - ture every smartclock clock divided by 8. if the sysclk is 24.5 mh z and the difference between two successive captures is 5984, then t he smartclock clock is as follows: 24.5 mhz/(5984/8) = 0.032754 mhz or 32.754 khz. this mode allows software to de termine the exact smartclock freque ncy in self-oscillate mode and the time between consecutive comparator 0 rising edges, which is useful fo r detecting changes in the capaci - tance of a touch sense switch. figure 25.6. timer 2 capture mode block diagram smartclock / 8 sysclk 0 1 t2xclk1 ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmr2l tmr2h tclk tr2 tmr2rll tmr2rlh capture tmr2cn t2split t2xclk1 tf2cen tf2l tf2h t2xclk0 tr2 tf2len tf2cen interrupt sysclk / 12 x0 t2xclk[1:0] 01 11 comparator 0 0 1 smartclock / 8 comparator 0 www.datasheet.in
rev. 1.0 289 c8051f99x-c8051f98x sfr page = 0x0; sfr addres s = 0xc8; bit-addressable sfr definition 25.8. tmr2cn: timer 2 control bit 7 6 5 4 3 2 1 0 name tf2h tf2l tf2len tf2cen t2split tr2 t2xclk[1:0] type r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7 tf2h timer 2 high byte overflow flag. set by hardware when the timer 2 high byte overflows from 0xff to 0x00. in 16 bit mode, this will occur when timer 2 overflows from 0xffff to 0x0000. when the timer 2 interrupt is enabled, setting this bit causes the cpu to vector to the timer 2 interrupt service routine. this bit is not automatically cleared by hardware. 6 tf2l timer 2 low byte overflow flag. set by hardware when the timer 2 low byte overflows from 0xff to 0x00. tf2l will be set when the low byte over flows regardless of the timer 2 mode. this bit is not automatically cleared by hardware. 5 tf2len timer 2 low byte interrupt enable. when set to 1, this bit enables timer 2 low byte interrupts. if timer 2 interrupts are also enabled, an interr upt will be generat ed when the low byte of timer 2 over - flows. 4 tf2cen timer 2 capture enable. when set to 1, this bit enables timer 2 capture mode. 3 t2split timer 2 split mode enable. when set to 1, timer 2 operates as two 8-bit timers with auto-reload. otherwise, timer 2 operates in 16-bit auto-reload mode. 2 tr2 timer 2 run control. timer 2 is enabled by setting this bit to 1. in 8-bit mode, this bit enables/disables tmr2h only; tmr2l is always enabled in split mode. 1:0 t2xclk[1:0] timer 2 external clock select. this bit selects the ?external? and ?capture trigger? clock sources for timer 2. if timer 2 is in 8-bit mode, this bit selects the ?external? clock source for both timer bytes. timer 2 clock select bits (t2mh and t2ml in register ckcon) may still be used to select between the ?external? clock and the system clock for either timer. note: external clock sources are sy nchronized with the system clock. 00: external clock is sysclk/12. capture trigger is smartclock/8. 01: external clock is comparator 0. capture trigger is smartclock/8. 10: external clock is sysclk/12. capture trigger is comparator 0. 11: external clock is smartclock/8 . capture trigger is comparator 0. www.datasheet.in
c8051f99x-c8051f98x 290 rev. 1.0 sfr page = 0x0; sfr address = 0xca sfr page = 0x0; sfr address = 0xcb sfr definition 25.9. tmr2rll: timer 2 relo ad register low byte bit 7 6 5 4 3 2 1 0 name tmr2rll[7:0] type r/w reset 00000000 bit name function 7:0 tmr2rll[7:0] timer 2 reload register low byte. tmr2rll holds the low byte of the reload value for timer 2. sfr definition 25.10. tmr2rlh: timer 2 relo ad register high byte bit 7 6 5 4 3 2 1 0 name tmr2rlh[7:0] type r/w reset 00000000 bit name function 7:0 tmr2rlh[7:0] timer 2 reload register high byte. tmr2rlh holds the high byte of the reload value for timer 2. www.datasheet.in
rev. 1.0 291 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xcc sfr page = 0x0; sfr address = 0xcd sfr definition 25.11. tmr2l: timer 2 low byte bit 7 6 5 4 3 2 1 0 name tmr2l[7:0] type r/w reset 00000000 bit name function 7:0 tmr2l[7:0] timer 2 low byte. in 16-bit mode, the tmr2l register contains the low byte of the 16-bit timer 2. in 8- bit mode, tmr2l contains the 8-bit low byte timer value. sfr definition 25.12. tmr2h timer 2 high byte bit 7 6 5 4 3 2 1 0 name tmr2h[7:0] type r/w reset 00000000 bit name function 7:0 tmr2h[7:0] timer 2 low byte. in 16-bit mode, the tmr2h register contains the high byte of the 16-bit timer 2. in 8- bit mode, tmr2h contains the 8-bit high byte timer value. www.datasheet.in
c8051f99x-c8051f98x 292 rev. 1.0 25.3. timer 3 timer 3 is a 16-bit timer formed by two 8-bit sfrs: tmr3l (low byte) and tmr3h (high byte). timer 3 may operate in 16-bit auto-reload mode or (split) 8-bit auto-reload mode. the t3split bit (tmr2cn.3) defines the timer 3 operation mode. timer 3 can also be used in c apture mode to measure the exte rnal oscillator source or the smartclock oscillator period with respect to another oscillator. timer 3 may be clocked by the system clock, the system clock divided by 12, external oscillator source divided by 8, or the smartclock oscillator. the exte rnal oscillator source di vided by 8 and smartclock oscillator is synchronize d with the system clock. 25.3.1. 16-bit timer with auto-reload when t3split (tmr3cn.3) is zero, timer 3 operates as a 16-bit timer with auto-reload. timer 3 can be clocked by sysclk, sysclk divided by 12, external oscillator clock sour ce divided by 8, or smartclock oscillator. as the 16-bit ti mer register increments and overflows from 0xffff to 0x 0000, the 16-bit value in the timer 3 reload registers (tmr3rlh and tmr3rll) is loaded into the timer 3 register as shown in figure 25.7 , and the timer 3 high byte overflow flag (tmr3cn. 7) is set. if timer 3 interrupts are enabled (if eie1.7 is set), an interrupt will be generated on each time r 3 overflow. additionally, if timer 3 interrupts are enabled and the tf3len bit is set (tmr3cn.5), an interrupt will be generated each ti me the lower 8 bits (tmr3l) overflow from 0xff to 0x00. figure 25.7. timer 3 16-bit mode block diagram sysclk tmr3l tmr3h tmr3rll tmr3rlh reload tclk 0 1 tr3 tmr3cn t3split t3xclk1 tf3cen tf3l tf3h t3xclk0 tr3 interrupt tf3len to adc ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m external clock / 8 sysclk / 12 00 t3xclk[1:0] 01 11 smartclock www.datasheet.in
rev. 1.0 293 c8051f99x-c8051f98x 25.3.2. 8-bit timers with auto-reload when t3split is set, timer 3 operates as two 8-bi t timers (tmr3h and tmr3l). both 8-bit timers oper - ate in auto-reload mode as shown in figure 25.8 . tmr3rll holds the reload value for tmr3l; tmr3rlh holds the reload value for tmr3h. the tr3 bit in tmr3cn handles the run control for tmr3h. tmr3l is always running when configured for 8-bit mode. each 8-bit timer may be configured to use sysclk, sysc lk divided by 12, the external oscillator clock source divided by 8, or the smartclock. the timer 3 clock select bits (t3mh and t3ml in ckcon) select either sysclk or t he clock defined by the timer 3 external clock select bits (t3xclk[1:0] in tmr3cn), as follows: the tf3h bit is set when tmr3h overflows from 0xff to 0x00; the tf3l bit is set when tmr3l overflows from 0xff to 0x00. when timer 3 interrupts are enabled, an interrupt is generated each time tmr3h over - flows. if timer 3 interrupts are enabled and tf3len (tmr3cn.5) is set, an interrupt is generated each time either tmr3l or tmr3h overflows. when tf3le n is enabled, software must check the tf3h and tf3l flags to determine the source of the timer 3 interrupt. the tf3h and tf3l interrupt flags are not cleared by hardware and must be manually cleared by software. figure 25.8. timer 3 8-bit mode block diagram t3mh t3xclk[1:0] tmr3h clock source t3ml t3xclk[1:0] tmr3l clock source 0 00 sysclk / 12 0 00 sysclk / 12 0 01 smartclock 0 01 smartclock 0 10 reserved 0 10 reserved 0 11 external clock / 8 0 11 external clock / 8 1 x sysclk 1 x sysclk sysclk tclk 0 1 tr3 1 0 tmr3h tmr3rlh reload reload tclk tmr3l tmr3rll interrupt tmr3cn t3split t3xclk1 tf3cen tf3len tf3l tf3h t3xclk0 tr3 to adc ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m external clock / 8 sysclk / 12 00 t3xclk[1:0] 01 11 smartclock www.datasheet.in
c8051f99x-c8051f98x 294 rev. 1.0 25.3.3. smartclock/external oscillator capture mode the capture mode in timer 3 allows either smartclock or the external oscillator period to be measured against the system clock or the system clock divided by 12. smartclock and the ex ternal oscillator period can also be compared against each other. setting tf3cen to 1 enables the smartclock/external oscillator capture mode for timer 3. in this mode, t3split should be set to 0, as the full 16-bit timer is used. when capture mode is e nabled, a capture event will be generated either ever y smartclock rising edge or every 8 external clock cycles, depending on the t3xclk1 setting. when the capture event occurs, the contents of timer 3 (tmr3h:tmr3l) are loaded into the timer 3 reload registers (tmr3rlh:tmr3rll) and the tf3h flag is set (triggering an interrupt if timer 3 interrupts are enabled). by recording the differ - ence between two successive timer capture values, the smartclock or external clock period can be determined with re spect to the timer 3 clock. the timer 3 clock should be much faster than the capture clock to achieve an accurate reading. for example, if t3ml = 1b, t3xclk1 = 0b, and tf3cen = 1b, timer 3 will clock every sysclk and cap - ture every smartclock rising edge. if sysclk is 24 .5 mhz and the difference between two successive captures is 350 counts, then the smartclock period is as follows: 350 x (1 / 24.5 mhz) = 14.2 s. this mode allows software to determine the exact frequency of th e external oscillator in c and rc mode or the time between consecutive smartclock rising edges , which is useful for determining the smartclock frequency. figure 25.9. timer 3 capture mode block diagram external clock/8 sysclk 0 1 t3xclk1 ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmr3l tmr3h tclk tr3 tmr3rll tmr3rlh capture tmr3cn t3split t3xclk1 tf3cen tf3l tf3h t3xclk0 tr3 tf3len tf3cen interrupt sysclk/12 x0 t3xclk[1:0] 01 11 smartclock 0 1 smartclock external clock/8 www.datasheet.in
rev. 1.0 295 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x91 sfr definition 25.13. tmr3cn: timer 3 control bit 7 6 5 4 3 2 1 0 name tf3h tf3l tf3len tf3cen t3split tr3 t3xclk[1:0] type r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7 tf3h timer 3 high byte overflow flag. set by hardware when the timer 3 high byte overflows from 0xff to 0x00. in 16 bit mode, this will occur when timer 3 overflows from 0xffff to 0x0000. when the timer 3 interrupt is enabled, setting this bit causes the cpu to vector to the timer 3 interrupt service routine. this bit is not automatically cleared by hardware. 6 tf3l timer 3 low byte overflow flag. set by hardware when the timer 3 low byte overflows from 0xff to 0x00. tf3l will be set when the low byte overflows regardless of the timer 3 mode. this bit is not automatically cleared by hardware. 5 tf3len timer 3 low byte interrupt enable. when set to 1, this bit enables timer 3 low byte inte rrupts. if timer 3 interrupts are also enabled, an interrupt will be ge nerated when the lo w byte of timer 3 overflows. 4 tf3cen timer 3 smartclock/external oscillator capture enable. when set to 1, this bit enables timer 3 capture mode. 3 t3split timer 3 split mode enable. when this bit is set, timer 3 operates as two 8-bit timers with auto-reload. 0: timer 3 operates in 16-bit auto-reload mode. 1: timer 3 operates as two 8-bi t auto-reload timers. 2 tr3 timer 3 run control. timer 3 is enabled by setting this bit to 1. in 8-bit mode, this bit enables/disables tmr3h only; tmr3l is alwa ys enabled in split mode. 1:0 t3xclk[1:0] timer 3 external clock select. this bit selects the ?external? and ?capture trigger? clock sources for timer 3. if timer 3 is in 8-bit mode, this bit selects the ?external? clock source for both timer bytes. timer 3 clock select bits (t3mh and t3ml in register ckcon) may still be used to select between the ?external? cl ock and the system cloc k for either timer. note: external clock sources are sy nchronized with the system clock. 00: external clock is sysclk /12. capture trigger is smartclock. 01: external clock is external oscilla tor/8. capture trigger is smartclock. 10: external clock is sysclk/12. capt ure trigger is exte rnal oscillator/8. 11: external clock is smar tclock. capture trigger is external oscillator/8. www.datasheet.in
c8051f99x-c8051f98x 296 rev. 1.0 sfr page = 0x0; sfr address = 0x92 sfr page = 0x0; sfr address = 0x93 sfr definition 25.14. tmr3rll: timer 3 relo ad register low byte bit 7 6 5 4 3 2 1 0 name tmr3rll[7:0] type r/w reset 00000000 bit name function 7:0 tmr3rll[7:0] timer 3 reload register low byte. tmr3rll holds the low byte of the reload value for timer 3. sfr definition 25.15. tmr3rlh: timer 3 relo ad register high byte bit 7 6 5 4 3 2 1 0 name tmr3rlh[7:0] type r/w reset 00000000 bit name function 7:0 tmr3rlh[7:0] timer 3 reload register high byte. tmr3rlh holds the high byte of the reload value for timer 3. www.datasheet.in
rev. 1.0 297 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0x94 sfr page = 0x0; sfr address = 0x95 sfr definition 25.16. tmr3l: timer 3 low byte bit 7 6 5 4 3 2 1 0 name tmr3l[7:0] type r/w reset 00000000 bit name function 7:0 tmr3l[7:0] timer 3 low byte. in 16-bit mode, the tmr3l register contains the low byte of the 16-bit timer 3. in 8-bit mode, tmr3l contains the 8-bit low byte timer value. sfr definition 25.17. tmr3h timer 3 high byte bit 7 6 5 4 3 2 1 0 name tmr3h[7:0] type r/w reset 00000000 bit name function 7:0 tmr3h[7:0] timer 3 high byte. in 16-bit mode, the tmr3h register contains the high byte of the 16-bit timer 3. in 8-bit mode, tmr3h contains the 8-bit high byte timer value. www.datasheet.in
c8051f99x-c8051f98x 298 rev. 1.0 26. programmable counter array the programmable counter array (pca0) provides enh anced timer functionality while requiring less cpu intervention than the standard 8051 counter/timers. th e pca consists of a dedicated 16-bit counter/timer and three 16-bit capture/compare modules. each capt ure/compare module has its own associated i/o line (cexn) which is routed through the crossbar to port i/o when enabled. the counter/timer is driven by a programmable timebase that can select between six sources: system clo ck, system clock divided by four, system clock divided by twelve, the ex ternal oscillator clock source divi ded by 8, smart clock divided by 8, timer 0 overflows, or an external clock signal on the eci input pin. each capture/compare module may be configured to operate independently in one of si x modes: edge-triggered capture, software timer, high-speed output, frequency outpu t, 8 to 11-bit pwm, or 16-bit pwm (each mode is described in section ?26.3. capture/comp are modules? on page 301) . the external oscillator clock option is ideal for real-time clock (rtc) functionality, allowing the pca to be clocked by a precision external oscillator while the internal oscillator drives the system clock. the pca is configur ed and controlled through the system controller's special function registers. the pca block diagram is shown in figure 26.1 important note: the pca module 2 may be used as a watchdog timer (wdt), and is enabled in this mode following a system reset. access to certain pca registers is restricted while wdt mode is enabled . see section 26.4 for details. figure 26.1. pca block diagram capture/compare module 1 capture/compare module 0 capture/compare module 2 / wdt cex1 eci crossbar cex2 cex0 port i/o 16-bit counter/timer pca clock mux sysclk/12 sysclk/4 timer 0 overflow eci sysclk external clock/8 smartclock/8 www.datasheet.in
rev. 1.0 299 c8051f99x-c8051f98x 26.1. pca counter/timer the 16-bit pca counter/timer consists of two 8-bi t sfrs: pca0l and pca0h. pca0h is the high byte (msb) of the 16-bit counter/timer and pca0l is the lo w byte (lsb). reading pc a0l automatically latches the value of pca0h into a ?snapshot? register; the following pca0h read accesses this ?snapshot? register. reading the pca0l register first guarantees an accu rate reading of the entire 16-bit pca0 counter. reading pca0h or pca0l does not disturb the counter operation. the cps2 ? cps0 bits in the pca0md register select the timebase for the counter/timer as shown in table 26.1. when the counter/timer overflows from 0xffff to 0x0 000, the counter overflow fl ag (cf) in pca0md is set to logic 1 and an interrupt request is generated if cf interrupts are enabled. setting the ecf bit in pca0md to logic 1 enables the cf flag to generate an interrupt request. the cf bit is not automatically cleared by hardware when the cpu vectors to the in terrupt service routine, and must be cleared by software. clearing the cidl bit in the pca0md register allows the pca to continue normal operation while the cpu is in idle mode. figure 26.2. pca counter/timer block diagram table 26.1. pca timebase input options cps2 cps1 cps0 timebase 000 system clock divided by 12 001 system clock divided by 4 010 timer 0 overflow 011 high-to-low transitions on eci (max rate = system clock divided by 4) 100 system clock 101 external oscillator source divided by 8 1 110 smartclock oscillator source divided by 8 2 111 reserved notes: 1. external oscillator source divided by 8 is synchronized with the system clock. 2. smartclock oscillator source divided by 8 is synchronized with the system clock. pca0cn c f c r c c f 0 c c f 2 c c f 1 pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 idle 0 1 pca0h pca0l snapshot register to sfr bus overflow to pca interrupt system cf pca0l read to pca modules sysclk/12 sysclk/4 timer 0 overflow eci 000 001 010 011 100 101 sysclk external clock/8 smartclock/8 110 www.datasheet.in
c8051f99x-c8051f98x 300 rev. 1.0 26.2. pca0 interrupt sources figure 26.3 shows a diagram of the pca interrupt tree . there are five independent event flags that can be used to generate a pca0 interrupt. they are: the main pca counter overflow flag (cf), which is set upon a 16-bit overflow of the pca0 counter, an intermediat e overflow flag (covf), which can be set on an overflow from the 8th, 9th, 10th, or 11th bit of t he pca0 counter, and the individual flags for each pca channel (ccf0, ccf1, and ccf2), which are set according to the operation mode of that module. these event flags are always set when the trigger condition occurs. each of these flags can be individually selected to generate a pca0 interrupt, using the co rresponding interrupt enable flag (ecf for cf, ecov for covf, and eccfn for each ccfn). pca0 interrupts must be globally enabled before any individual interrupt sources are recognized by the processor. pc a0 interrupts are globally enabled by setting the ea bit and the epca0 bit to logic 1. figure 26.3. pca interrupt block diagram pca0cn c f c r c c f 0 c c f 2 c c f 1 pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 0 1 pca module 0 (ccf0) pca module 1 (ccf1) eccf1 0 1 eccf0 0 1 pca module 2 (ccf2) eccf2 pca counter/timer 16- bit overflow 0 1 interrupt priority decoder epca0 0 1 ea 0 1 pca0cpmn (for n = 0 to 2) p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n pca counter/timer 8, 9, 10 or 11-bit overflow 0 1 set 8, 9, 10, or 11 bit operation pca0pwm a r s e l e c o v c l s e l 0 c l s e l 1 c o v f www.datasheet.in
rev. 1.0 301 c8051f99x-c8051f98x 26.3. capture/compare modules each module can be configured to operate independent ly in one of six operation modes: edge-triggered capture, software timer, high-speed output, frequency output, 8 to 11-bit pulse width modulator, or 16-bit pulse width modulator. each module has special functi on registers (sfrs) associ ated with it in the cip- 51 system controller. these registers are used to exchange data with a module and configure the module's mode of operation. table 26.2 summarizes the bit settings in the pca0cpmn and pca0pwm registers used to select the pca capture/compare module?s oper ating mode. note that all modules set to use 8, 9, 10, or 11-bit pwm mode must use the same cycle length (8?11 bits). setting the eccfn bit in a pca0cpmn register enables the module's ccfn interrupt. table 26.2. pca0cpm and pca0pwm bit settings for pca capture/compare modules operational mode pca0cpmn pca0pwm bit number 76543210765 4?2 1?0 capture triggered by positive edge on cexn xx10000a0xbxxx xx capture triggered by negative edge on cexn xx01000a0xbxxx xx capture triggered by any transition on cexn xx11000a0xbxxx xx software timer xc00100a0xbxxx xx high speed output xc00110a0xbxxx xx frequency output xc00011a0xbxxx xx 8-bit pulse width modulator (note 7) 0 c 0 0 e 0 1 a 0 x b xxx 00 9-bit pulse width modulator (note 7) 0 c 0 0 e 0 1 a d x b xxx 01 10-bit pulse width modulator (note 7) 0 c 0 0 e 0 1 a d x b xxx 10 11-bit pulse width modulator (note 7) 0 c 0 0 e 0 1 a d x b xxx 11 16-bit pulse width modulator 1 c 0 0 e 0 1 a 0 x b xxx xx notes: 1. x = don?t care (no functional difference for individual module if 1 or 0). 2. a = enable interrupts for this module (pca interrupt triggered on ccfn set to 1). 3. b = enable 8th, 9th, 10th or 11th bit overfl ow interrupt (depends on setting of clsel[1:0]). 4. c = when set to 0, the digital comparator is off. for high speed and frequency output modes, the associated pin will not toggle. in any of the pwm modes, this generates a 0% duty cycle (output = 0). 5. d = selects whether the capture/compare register (0) or the auto-reload register (1) for the associated channel is accessed via addresses pca0cphn and pca0cpln. 6. e = when set, a match event will cause the ccfn flag for the associated channel to be set. 7. all modules set to 8, 9, 10 or 11-bit pw m mode use the same cycle length setting. www.datasheet.in
c8051f99x-c8051f98x 302 rev. 1.0 26.3.1. edge-triggered capture mode in this mode, a valid transition on the cexn pi n causes the pca to capture the value of the pca counter/timer and load it into the corresponding mo dule's 16-bit capture/compar e register (pca0cpln and pca0cphn). the cappn and capnn bits in the pca0cp mn register are used to select the type of transition that triggers the capture: low-to-high transi tion (positive edge), high -to-low transition (negative edge), or either transition (positive or negative ed ge). when a capture occurs, the capture/compare flag (ccfn) in pca0cn is set to logic 1. an interrupt request is generated if the ccfn interrupt for that module is enabled. the ccfn bit is not automatically cleared by hardware when the cpu vectors to the interrupt service routine, and mu st be cleared by soft ware. if both cappn and capnn bi ts are set to logic 1, then the state of the port pin associated with cexn can be read directly to determi ne whether a rising-edge or falling-edge caused the capture. figure 26.4. pca capture mode diagram note: the cexn input sign al must remain high or lo w for at least 2 system clock cycles to be recognized by the hardware. pca0l pca0cpln pca timebase cexn crossbar port i/o pca0h capture pca0cphn 0 1 0 1 (to ccfn) pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n pca0cn c f c r c c f 0 c c f 2 c c f 1 pca interrupt x 000x x www.datasheet.in
rev. 1.0 303 c8051f99x-c8051f98x 26.3.2. software timer (compare) mode in software timer mode, the pca c ounter/timer value is compared to the module's 16-bit capture/compare register (pca0cphn and pca0cpln). when a match occurs, the capture/compare flag (ccfn) in pca0cn is set to logic 1. an interrupt request is generated if the ccfn interrupt for that module is enabled. the ccfn bit is not automatically cleared by hardware when the cpu vectors to the interrupt service routine, and must be cleared by software. setting the ecomn and matn bits in the pca0cpmn register enables software timer mode. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln clears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. figure 26.5. pca software timer mode diagram match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln 00 00 0 1 x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x pca0cn c f c r c c f 0 c c f 2 c c f 1 pca interrupt www.datasheet.in
c8051f99x-c8051f98x 304 rev. 1.0 26.3.3. high-speed output mode in high-speed output mode, a module?s associated cexn pin is toggled each time a match occurs between the pca counter and the module's 16- bit capture/compare register (pca0cphn and pca0cpln). when a match occurs, the capture/compare flag (ccfn) in pca0cn is set to logic 1. an interrupt request is generated if the ccfn interrupt for that module is enabled. the ccfn bit is not automatically cleared by hardware when the cpu vect ors to the interrupt service routine, and must be cleared by software. setting the togn, matn, and ecomn bits in the pca0cpmn register enables the high-speed output mode. if ecomn is cleared, the associated pin will retain its state, and not toggle on the next match event. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln clears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. figure 26.6. pca high-speed output mode diagram 26.3.4. frequency output mode frequency output mode produces a programmable-freq uency square wave on the module?s associated cexn pin. the capture/compare module high byte hol ds the number of pca clocks to count before the output is toggled. the frequency of the s quare wave is then defined by equation 26.1. equation 26.1. square wave frequency output match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln 0 1 00 0x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x cexn crossbar port i/o toggle 0 1 togn pca0cn c f c r c c f 0 c c f 2 c c f 1 pca interrupt f cexn f pca 2 pca 0 cphn ? ------------------- --------------------- - = note: a value of 0x00 in the pca0cphn re gister is equal to 256 for this equation. www.datasheet.in
rev. 1.0 305 c8051f99x-c8051f98x where f pca is the frequency of the clock selected by the cps2 ? 0 bits in the pca mode register, pca0md. the lower byte of the capture/compare modu le is compared to the pca counter low byte; on a match, cexn is toggled and the offset held in the hi gh byte is added to the matched value in pca0cpln. frequency output mode is enabled by setting the ecomn, togn, and pwmn bits in the pca0cpmn register. note that the matn bit should normally be set to 0 in this mode. if the ma tn bit is set to 1, the ccfn flag for the channel will be set when the 16-bit pca0 counter and the 16-bit capture/compare register for the channel are equal. figure 26.7. pca frequency output mode 26.3.5. 8-bit, 9-bit, 10-bit and 11-bit pulse width modulator modes each module can be used independently to gener ate a pulse width modulated (pwm) output on its associated cexn pin. the frequency of the output is dependent on the timebase for the pca counter/timer, and the setting of the pwm cycle length (8, 9, 10 or 11-bits). for backwards- compatibility with the 8-bit pwm mode available on other devices, the 8-bit pwm mode operates slightly different than 9, 10 and 11- bit pwm modes. it is important to note that all channels configured for 8/9/10/11-bit pwm mode will use the same cycle length. it is not possible to configure one channel for 8-bit pwm mode and another for 11-bit mode (for example). however, other pca channels can be configured to pin capture, high- speed output, software timer, frequency output, or 16-bit pwm mode independently. 8-bit comparator pca0l enable pca timebase match pca0cphn 8-bit adder pca0cpln adder enable cexn crossbar port i/o toggle 0 1 togn 000 x pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x enb enb 0 1 write to pca0cpln write to pca0cphn reset www.datasheet.in
c8051f99x-c8051f98x 306 rev. 1.0 26.3.5.1. 8-bit pulse width modulator mode the duty cycle of the pwm output signal in 8-bit pw m mode is varied using the module's pca0cpln capture/compare register. when the value in the low by te of the pca counter/timer (pca0l) is equal to the value in pca0cpln, the output on th e cexn pin will be set. when the coun t value in pca0l overflows, the cexn output will be reset (see figure 26.8). also, when the counter/timer low byte (pca0l) overflows from 0xff to 0x00, pca0cpln is reloaded automatically with the value stored in the module?s capture/compare high byte (pca0cphn) without software intervention. setting the ecomn and pwmn bits in the pca0cpmn register, and setting the clsel bits in register pca0pwm to 00b enables 8-bit pulse width modulator mode. if the matn bit is se t to 1, the ccfn flag for the modu le will be set each time an 8-bit comparator match (rising edge) occurs. the covf flag in pca0pwm can be used to detect the overflow (falling edge), which will occur every 256 pca clock cyc les. the duty cycle for 8-bit pwm mode is given in equation 26.2. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln clears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. equation 26.2. 8-bit pwm duty cycle using equation 26.2, the largest duty cycle is 100 % (pca0cphn = 0), and the smallest duty cycle is 0.39% (pca0cphn = 0xff). a 0% duty cycle may be generated by clearing the ecomn bit to 0. figure 26.8. pca 8-bit pwm mode diagram duty cycle 256 pca 0 cphn ? ?? 256 ------------------ ----------------- ---------------- = 8-bit comparator pca0l pca0cpln pca0cphn cexn crossbar port i/o enable overflow pca timebase 00x0 x q q set clr s r match pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 pca0pwm a r s e l e c o v c l s e l 0 c l s e l 1 c o v f x0 0 0 enb enb 0 1 write to pca0cpln write to pca0cphn reset covf www.datasheet.in
rev. 1.0 307 c8051f99x-c8051f98x 26.3.5.2. 9/10/11-bit pulse width modulator mode the duty cycle of the pwm output signa l in 9/10/11-bit pwm mode should be varied by writing to an ?auto- reload? register, which is dual-mapped into the pc a0cphn and pca0cpln register locations. the data written to define the duty cycle should be right-just ified in the registers. the auto-reload registers are accessed (read or written) when the bit arsel in pca0pwm is set to 1. the capture/compare registers are accessed when arsel is set to 0. when the least-significant n bits of the pca0 co unter match the value in the associated module?s capture/compare register (pca0cpn), the output on cexn is asserted high. when the counter overflows from the nth bit, cexn is asserted low (see figure 26 .9). upon an overflow from the nth bit, the covf flag is set, and the value stored in the module?s auto-r eload register is loaded into the capture/compare register. the value of n is determined by the clsel bits in register pca0pwm. the 9, 10 or 11-bit pwm mode is selected by se tting the ecomn and pwmn bits in the pca0cpmn register, and setting the clsel bits in register pca0pwm to the desired cycle length (other than 8-bits). if the matn bit is set to 1, the ccfn flag for the mo dule will be set each time a comparator match (rising edge) occurs. the covf flag in pc a0pwm can be used to detect the overflow (falling edge), which will occur every 512 (9-bit), 1024 (10-bit) or 2048 (11-bi t) pca clock cycles. the duty cycle for 9/10/11-bit pwm mode is given in equation 26.2, where n is the number of bits in the pwm cycle. important note about pca0cphn and pca0cpln registers : when writing a 16-bit value to the pca0cpn registers, the low byte should always be wr itten first. writing to pca0cpln clears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. equation 26.3. 9, 10, and 11-bit pwm duty cycle a 0% duty cycle may be generated by clearing the ecomn bit to 0. figure 26.9. pca 9, 10 and 11-bit pwm mode diagram duty cycle 2 n pca 0 cpn ? ?? 2 n ------------------ -------------- ----------- - = n-bit comparator pca0h:l (capture/compare) pca0cph:ln (right-justified) (auto-reload) pca0cph:ln (right-justified) cexn crossbar port i/o enable overflow of n th bit pca timebase 00x0 x q q set clr s r match pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 pca0pwm a r s e l e c o v c l s e l 0 c l s e l 1 c o v f x enb enb 0 1 write to pca0cpln write to pca0cphn reset r/w when arsel = 1 r/w when arsel = 0 set ?n? bits: 01 = 9 bits 10 = 10 bits 11 = 11 bits www.datasheet.in
c8051f99x-c8051f98x 308 rev. 1.0 26.3.6. 16-bit pulse width modulator mode a pca module may also be operated in 16-bit pwm mode. 16-bit pwm mode is independent of the other (8/9/10/11-bit) pwm modes. in this mode, the 16-bit capture/compare module defines the number of pca clocks for the low time of the pwm signal. when the pca counter matches the module contents, the output on cexn is asserted high; when the 16-bit counter overflows, cexn is asserted low. to output a varying duty cycle, new value writes should be synchronized with pca ccfn match interrupts. 16-bit pwm mode is enabled by setting the ecomn, pwmn, and pwm16n bits in the pca0cpmn register. for a varying duty cycle, match interrupts should be enabled (eccfn = 1 and matn = 1) to help synchronize the capture/compar e register writes. if the matn bit is set to 1, the ccfn flag for the module will be set each time a 16-bit comparator match (rising edge) oc curs. the cf flag in pca0cn can be used to detect the overflow (falling edge). the duty cycle for 16-bit pwm mode is given by equation 26.4. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln clears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. equation 26.4. 16-bit pwm duty cycle using equation 26.4, the largest duty cycle is 100% (pca0cpn = 0), and the smallest duty cycle is 0.0015% (pca0cpn = 0xffff). a 0% duty cycle may be generated by clearing the ecomn bit to 0. figure 26.10. pca 16-bit pwm mode duty cycle 65536 pca 0 cpn ? ?? 65536 ------------------ ------------------ ---------------- - = pca0cpln pca0cphn enable pca timebase 00x0 x pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 1 16-bit comparator cexn crossbar port i/o overflow q q set clr s r match pca0h pca0l enb enb 0 1 write to pca0cpln write to pca0cphn reset www.datasheet.in
rev. 1.0 309 c8051f99x-c8051f98x 26.4. watchdog timer mode a programmable watchdog timer (wdt) function is avai lable through the pca module 2. the wdt is used to generate a reset if the time between writes to th e wdt update register (pca0cph2) exceed a specified limit. the wdt can be configured and enabled/disabled as needed by software. with the wdte bit set in the pca0md register, mo dule 2 operates as a watchdog timer (wdt). the module 2 high byte is compared to the pca counter high byte; the module 2 low byte holds the offset to be used when wdt updates are performed. the watchdog timer is enabled on reset. writes to some pca registers are restricted while the watchdog timer is enabled. the wdt will generate a reset shortly after code begins execution. to avoid this reset, the wdt should be explicitly disabled (and optionally re-configured and re-enabled if it is used in the system). 26.4.1. watchdog timer operation while the wdt is enabled: ? pca counter is forced on. ? writes to pca0l and pca0h are not allowed. ? pca clock source bits (cps2 ? cps0) are frozen. ? pca idle control bit (cidl) is frozen. ? module 2 is forced into software timer mode. ? writes to the module 2 mode register (pca0cpm2) are disabled. while the wdt is enabled, writes to the cr bit will not change the pca counter state; the counter will run until the wdt is disabled. the pca counter run control bit (cr) will re ad zero if the wdt is enabled but user software has not enabled th e pca counter. if a match occurs between pca0cph2 and pca0h while the wdt is enabled, a reset will be generated. to pr event a wdt reset, the wd t may be up dated with a write of any value to pca0cph2. up on a pca0cph2 write, pca0h plus the offset held in pca0cpl2 is loaded into pca0cph2 (see figure 26.11). figure 26.11. pca module 2 with watchdog timer enabled pca0h enable pca0l overflow reset pca0cpl2 8-bit adder pca0cph2 adder enable pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 match write to pca0cph2 8-bit comparator www.datasheet.in
c8051f99x-c8051f98x 310 rev. 1.0 the 8-bit offset held in pca0cph2 is compared to th e upper byte of the 16-bit pca counter. this offset value is the number of pca0l overflows before a re set. up to 256 pca clocks may pass before the first pca0l overflow occurs, depending on the value of the pca0l when the update is performed. the total offset is then given (in pca clocks) by equation 26.5 , where pca0l is the value of the pca0l register at the time of the update. equation 26.5. watchdog timer offset in pca clocks the wdt reset is generated when pca0l overflow s while there is a match between pca0cph2 and pca0h. software may force a wdt reset by writing a 1 to the ccf2 flag (pca0cn.2) while the wdt is enabled. 26.4.2. watchdog timer usage to configure the wdt, perform the following tasks: 1. disable the wdt by writing a 0 to the wdte bit. 2. select the desired pca clock source (with the cps2 ? cps0 bits). 3. load pca0cpl2 with the desi red wdt update offset value. 4. configure the pca idle mode (set cidl if the wdt should be suspended while the cpu is in idle mode). 5. enable the wdt by setting the wdte bit to 1. 6. reset the wdt timer by writing to pca0cph2. the pca clock source and idle mode select cannot be changed while the wdt is enabled. the watchdog timer is enabled by setting the wdte or wdlck bits in the pca0md register. when wdlck is set, the wdt cannot be disabled until the next system reset. if wdlck is not set, the wdt is disabled by clearing the wdte bit. the wdt is enabled following any rese t. the pca0 counter clock defaults to the system clock divided by 12, pca0l defaults to 0x00, and pca0cpl2 defaults to 0x00. using equation 26.5, this results in a wdt timeout interval of 256 pca clock cycles, or 3072 system clock cycles. table 26.3 lists some example timeout intervals for typical system clocks. table 26.3. watchdog timer timeout intervals 1 system clock (hz) pca0cpl2 timeout interval (ms) 24,500,000 255 32.1 24,500,000 128 16.2 24,500,000 32 4.1 3,062,500 2 255 257 3,062,500 2 128 129.5 3,062,500 2 32 33.1 32,000 255 24576 32,000 128 12384 32,000 32 3168 notes: 1. assumes sysclk/12 as the pca clock source, and a pca0l value of 0x00 at the update time. 2. internal sysclk reset frequency = internal oscillator divided by 8. offset 256 pca 0 cpl 2 ? ?? 256 pca 0 l ? ?? + = www.datasheet.in
rev. 1.0 311 c8051f99x-c8051f98x 26.5. register descriptions for pca0 following are detailed descriptions of the special func tion registers related to the operation of the pca. sfr page = 0x0; sfr addres s = 0xd8; bit-addressable sfr definition 26.1. pca0cn: pca control bit76543210 name cf cr ccf2 ccf1 ccf0 type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7cf pca counter/timer overflow flag. set by hardware when the pca counter/timer overflows from 0xffff to 0x0000. when the counter/timer overflow (cf) interrupt is enabled, setting this bit causes the cpu to vector to the pca interrupt service r outine. this bit is not automatically cleared by hardware and must be cleared by software. 6cr pca counter/timer run control. this bit enables/disables the pca counter/timer. 0: pca counter/timer disabled. 1: pca counter/timer enabled. 5:3 unused read = 000b, write = don't care. 2:0 ccf[2:0] pca module n capture/compare flag. these bits are set by hardware when a matc h or capture occurs in the associated pca module n. when the ccfn interrupt is en abled, setting this bi t causes the cpu to vector to the pca interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by software. www.datasheet.in
c8051f99x-c8051f98x 312 rev. 1.0 sfr page = 0x0; sfr address = 0xd9 sfr definition 26.2 . pca0md: pca mode bit76543210 name cidl wdte wdlck cps2 cps1 cps0 ecf type r/w r/w r/w r r/w r/w r/w r/w reset 01000000 bit name function 7cidl pca counter/timer idle control. specifies pca behavior when cpu is in idle mode. 0: pca continues to function normally while the system co ntroller is in idle mode. 1: pca operation is suspended while th e system controller is in idle mode. 6wdte watchdog timer enable. if this bit is set, pca module 2 is used as the watchdog timer. 0: watchdog timer disabled. 1: pca module 2 enabled as watchdog timer. 5 wdlck watchdog timer lock. this bit locks/unlocks the watchdog timer e nable. when wdlck is set, the watchdog timer may not be disabled until the next system reset. 0: watchdog timer enable unlocked. 1: watchdog timer enable locked. 4 unused read = 0b, write = don't care. 3:1 cps[2:0] pca counter/timer pulse select. these bits select the timebase source for the pca counter 000: system clock divided by 12 001: system clock divided by 4 010: timer 0 overflow 011: high-to-low transitions on eci (max rate = system clock divided by 4) 100: system clock 101: external clock divided by 8 (synchronized with the system clock) 110: smartclock divided by 8 (synchronized with the system clock) 111: reserved 0ecf pca counter/timer overflow interrupt enable. this bit sets the masking of the pca co unter/timer overflow (cf) interrupt. 0: disable the cf interrupt. 1: enable a pca counter/timer overflow in terrupt request when cf (pca0cn.7) is set. note: when the wdte bit is set to 1, the other bits in t he pca0md register cannot be modified. to change the contents of the pca0md register, the watchdog timer must first be disabled. www.datasheet.in
rev. 1.0 313 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xdf sfr definition 26.3. pca0pw m: pca pwm configuration bit76543210 name arsel ecov covf clsel[1:0] type r/w r/w r/w r r r r/w reset 00000000 bit name function 7arsel auto-reload register select. this bit selects whether to read and write the normal pca capture/compare registers (pca0cpn), or the auto-reload registers at the same sfr addresses. this function is used to define the reload value for 9, 10, and 11-bit pwm modes. in all other modes, the auto-reload registers have no function. 0: read/write capture/compare registers at pca0cphn and pca0cpln. 1: read/write auto-reload regi sters at pca0cphn and pca0cpln. 6ecov cycle overflow interrupt enable. this bit sets the masking of the cycle overflow flag (covf) interrupt. 0: covf will not gene rate pca interrupts. 1: a pca interrupt will be ge nerated when covf is set. 5covf cycle overflow flag. this bit indicates an overflow of the 8th, 9th, 10th, or 11th bit of the main pca counter (pca0). the specific bit used for this flag depends on the setting of the cycle length select bits. the bit can be set by hardware or software, but must be cleared by soft- ware. 0: no overflow has occurred since the last time this bit was cleared. 1: an overflow has occurred since t he last time this bit was cleared. 4:2 unused read = 000b; write = don?t care. 1:0 clsel[1:0] cycle length select. when 16-bit pwm mode is not selected, th ese bits select the length of the pwm cycle, between 8, 9, 10, or 11 bits. this affects all channels configured for pwm which are not using 16-bit pwm mode. these bits ar e ignored for individual channels config- ured to16-bit pwm mode. 00: 8 bits. 01: 9 bits. 10: 10 bits. 11: 11 bits. www.datasheet.in
c8051f99x-c8051f98x 314 rev. 1.0 sfr address, page: pca0cpm0 = 0xda , 0x0; pca0cpm1 = 0xdb , 0x0; pca0cpm2 = 0xdc, 0x0 sfr definition 26.4. pca0cpmn : pca capture/compare mode bit76543210 name pwm16n ecomn cappn capnn matn togn pwmn eccfn type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7pwm16n 16-bit pulse width modulation enable. this bit enables 16-bit mode when pulse width modulation mode is enabled. 0: 8 to 11-bit pwm selected. 1: 16-bit pwm selected. 6ecomn comparator function enable. this bit enables the comparator function for pca module n when set to 1. 5 cappn capture positive function enable. this bit enables the positive edge capture for pca module n when set to 1. 4 capnn capture negative function enable. this bit enables the negative edge capture for pca module n when set to 1. 3matn match function enable. this bit enables the match function for pca module n when set to 1. when enabled, matches of the pca counter with a module's capture/compare regist er cause the ccfn bit in pca0md register to be set to logic 1. 2togn toggle function enable. this bit enables the toggle function for pca module n when set to 1. when enabled, matches of the pca counter with a module's capture/compare register cause the logic level on the cexn pin to toggle . if the pwmn bit is also set to logic 1, the module oper- ates in frequency output mode. 1pwmn pulse width modulation mode enable. this bit enables the pwm function for pca module n when set to 1. when enabled, a pulse width modulated signal is output on the cexn pin. 8 to 11-bit pwm is used if pwm16n is cleared; 16-bit mode is used if pwm1 6n is set to logic 1. if the togn bit is also set, the module operates in frequency output mode. 0eccfn capture/compare flag interrupt enable. this bit sets the masking of the ca pture/compare flag (ccfn) interrupt. 0: disable ccfn interrupts. 1: enable a capture/compare flag interrupt request when ccfn is set. note: when the wdte bit is set to 1, the pca0cpm5 regi ster cannot be modified, and module 5 acts as the watchdog timer. to change the contents of the pca0cpm5 register or the function of module 5, the watchdog timer must be disabled. www.datasheet.in
rev. 1.0 315 c8051f99x-c8051f98x sfr page = 0x0; sfr address = 0xf9 sfr page = 0x0; sfr address = 0xfa sfr definition 26.5. pca0l: pca counter/timer low byte bit76543210 name pca0[7:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:0 pca0[7:0] pca counter/timer low byte. the pca0l register holds the low byte (lsb) of the 16-bit pca counter/timer. note: when the wdte bit is set to 1, the pca0l register canno t be modified by software. to change the contents of the pca0l register, the watchdog timer must first be disabled. sfr definition 26.6. pca0h: pca counter/timer high byte bit76543210 name pca0[15:8] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:0 pca0[15:8] pca counter/timer high byte. the pca0h register holds the high byte (msb) of the 16-bit pca counter/timer. reads of this register will re ad the contents of a ?snapshot ? register, whose contents are updated only when the contents of pca0l are read (see section 26.1). note: when the wdte bit is set to 1, the pca0h register cannot be modified by software. to change the contents of the pca0h register, the watchdog timer must first be disabled. www.datasheet.in
c8051f99x-c8051f98x 316 rev. 1.0 sfr addresses: pca0cpl0 = 0xfb , pca0cpl1 = 0xe9 , pca0cpl2 = 0xeb sfr pages: pca0cpl0 = 0x0 , pca0cpl1 = 0x0 , pca0cpl2 = 0x0, sfr addresses: pca0cph0 = 0xfc , pca0cph1 = 0xea , pca0cph2 = 0xec sfr pages: pca0cph0 = 0x0 , pca0cph1 = 0x0 , pca0cph2 = 0x0, sfr definition 26.7. pca0cpln : pca capture module low byte bit76543210 name pca0cpn[7:0] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:0 pca0cpn[7:0] pca capture module low byte. the pca0cpln register holds the low byte (lsb) of the 16-bit capture module n. this register address also allows acce ss to the low byte of the corresponding pca channel?s auto-reload value for 9, 10, or 11-bit pwm mode. the arsel bit in register pca0pwm controls which register is accessed. note: a write to this register will clear the module?s ecomn bit to a 0. sfr definition 26.8. pca0cphn: pca capture module high byte bit76543210 name pca0cpn[15:8] type r/w r/w r/w r/w r/w r/w r/w r/w reset 00000000 bit name function 7:0 pca0cpn[15:8] pca capture module high byte. the pca0cphn register holds the high byte (msb) of the 16-bit capture module n. this register address also allows access to the high byte of the corresponding pca channel?s auto-reload value for 9, 10, or 11-bit pwm mode. the arsel bit in register pca0pwm controls which register is accessed. note: a write to this register will set the module?s ecomn bit to a 1. www.datasheet.in
rev. 1.0 317 c8051f99x-c8051f98x 27. c2 interface c8051f99x-c8051f98x devices includ e an on-chip silicon labs 2-wire (c2) debug interface to allow flash programming and in-system debugging with the produ ction part installed in the end application. the c2 interface uses a clock signal (c2ck) and a bi-direc tional c2 data signal (c2d) to transfer information between the device and a hos t system. see the c2 interface specificat ion for details on the c2 protocol. 27.1. c2 interface registers the following describes the c2 registers necessary to perform flash programming through the c2 inter - face. all c2 registers are accessed through the c2 inte rface as described in the c2 interface specification. c2 register definition 27.1. c2add: c2 address bit 7 6 5 4 3 2 1 0 name c2add[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 c2add[7:0] c2 address. the c2add register is accessed via the c2 interface to select the target data register for c2 data read and data write commands. address description 0x00 selects the device id register for data read instructions 0x01 selects the revision id register for data read instructions 0x02 selects the c2 flash programming control register for data read/write instructions 0xb4 selects the c2 flash programm ing data register for data read/write instructions www.datasheet.in
c8051f99x-c8051f98x 318 rev. 1.0 c2 address: 0x00 c2 address: 0x01 c2 register definition 27.2. deviceid: c2 device id bit 7 6 5 4 3 2 1 0 name deviceid[7:0] type r/w reset 0 0 0 1 0 1 0 0 bit name function 7:0 deviceid[7:0] device id. this read-only register returns the 8-bit device id: ? 0x25. c2 register definition 27.3. revid: c2 revision id bit 7 6 5 4 3 2 1 0 name revid[7:0] type r/w reset varies varies varies varies varies varies varies varies bit name function 7:0 revid[7:0] revision id. this read-only register returns the 8-bit revision id. for example: 0x00 = revision a. www.datasheet.in
rev. 1.0 319 c8051f99x-c8051f98x c2 address: 0x02 c2 address: 0xb4 c2 register definition 27.4. fpctl: c2 flash programming control bit 7 6 5 4 3 2 1 0 name fpctl[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 fpctl[7:0] flash programming control register. this register is used to enable flash programming via the c2 interface. to enable c2 flash programming, the following codes must be written in order: 0x02, 0x01. note that once c2 flash programming is ena bled, a system reset must be issued to resume normal operation. c2 register definition 27.5. fpdat: c2 flash programming data bit 7 6 5 4 3 2 1 0 name fpdat[7:0] type r/w reset 0 0 0 0 0 0 0 0 bit name function 7:0 fpdat[7:0] c2 flash programming data register. this register is used to pass flash commands, addresses, and data during c2 flash accesses. valid commands are listed below. code command 0x06 flash block read 0x07 flash block write 0x08 flash page erase 0x03 device erase www.datasheet.in
c8051f99x-c8051f98x 320 rev. 1.0 27.2. c2 pin sharing the c2 protocol allows the c2 pins to be shared wi th user functions so that in-system debugging and flash programming may be performed. this is possible because c2 communication is typically performed when the device is in the halt state, where all on-chip peripherals and user software are stalled. in this halted state, the c2 interface ca n safely ?borrow? the c2ck ( rst ) and c2d pins. in most applications, external resistors are required to isolate c2 interface traffic from the user application. a typical isolation configuration is shown in figure 27.1 . figure 27.1. typical c2 pin sharing the configuration in figure 27.1 assumes the following: 1. the user input (b) cannot change stat e while the target device is halted. 2. the rst pin on the target device is used as an input only. additional resistors may be necessary depending on the specific application. c2d c2ck rst (a) input (b) output (c) c2 interface master c8051fxxx www.datasheet.in
rev. 1.0 321 c8051f99x-c8051f98x d ocument c hange l ist revision 0.3 to revision 0.4 ? qfn-20 package and landing diagram updated. revision 0.4 to revision 1.0 ? iref0cf register description updated. ? updated adc0 chapter text. ? corrected an error in the product selector guide. ? updated smartclock chapter to indicate how the alarm value should be set when using auto reset and the lfo. ? updated electrical specifications to fill tbds and updated power specifications based on rev b characterization data. ? added a note to the oscicl register description. ? added a note to the crc0cn register description. ? updated equation in the crc0cnt register description. ? updated power on reset description. www.datasheet.in
c8051f99x-c8051f98x 322 rev. 1.0 c ontact i nformation silicon laboratories inc. 400 west cesar chavez ? austin, tx 78701 please visit the silicon labs technical support web page: ? https://www.silabs.com/support/pages/contacttechnicalsupport.aspx ? and register to submit a technical support request. silicon laboratories and silicon labs are trademarks of silicon laboratories inc. other products or brandnames mentioned herein are trademarks or registered trademarks of their respective holders the information in this document is believed to be accurate in al l respects at the time of publ ication but is subject to change without notice. silicon laboratories assumes no responsibility for erro rs and omissions, and disclaims responsibility for any consequen ces resulting from the use of information included herein. additi onally, silicon laboratories assumes no responsibility for the fun ction- ing of undescribed features or parameters. silicon laboratories re serves the right to make change s without further notice. sili con laboratories makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpos e, nor does silicon laboratories assume any liability arising out of the application or use of any product or circuit, and specifi cally disclaims any and all liability, including without limitation c onsequential or incidental damages. silicon laboratories product s are not designed, intended, or authorized for use in applications in tended to support or sustain life, or for any other application in which the failure of the silicon laboratories product could create a si tuation where personal injury or death may occur. should buyer purchase or use silicon laboratories prod ucts for any such unintended or unauthorized application, buyer shall indemnify and hold silicon laboratories harmless against all claims and damages. www.datasheet.in


▲Up To Search▲   

 
Price & Availability of C8051F980

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X